
(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 21 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}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* 0.5 (- phi1 phi2))))
(t_1 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_2 (+ (pow (sin (* -0.5 phi2)) 2.0) (* t_1 (cos phi2))))
(t_3 (fma t_0 t_0 (* t_1 (cos phi1)))))
(if (<= phi2 0.055)
(* R (* 2.0 (atan2 (sqrt t_3) (sqrt (- 1.0 t_3)))))
(* R (* 2.0 (atan2 (sqrt t_2) (sqrt (- 1.0 t_2))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin((0.5 * (phi1 - phi2)));
double t_1 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_2 = pow(sin((-0.5 * phi2)), 2.0) + (t_1 * cos(phi2));
double t_3 = fma(t_0, t_0, (t_1 * cos(phi1)));
double tmp;
if (phi2 <= 0.055) {
tmp = R * (2.0 * atan2(sqrt(t_3), sqrt((1.0 - t_3))));
} else {
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(phi1 - phi2))) t_1 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_2 = Float64((sin(Float64(-0.5 * phi2)) ^ 2.0) + Float64(t_1 * cos(phi2))) t_3 = fma(t_0, t_0, Float64(t_1 * cos(phi1))) tmp = 0.0 if (phi2 <= 0.055) 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(t_2), sqrt(Float64(1.0 - t_2))))); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $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[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$1 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$0 * t$95$0 + N[(t$95$1 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, 0.055], 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[t$95$2], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\\
t_1 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_2 := {\sin \left(-0.5 \cdot \phi_2\right)}^{2} + t\_1 \cdot \cos \phi_2\\
t_3 := \mathsf{fma}\left(t\_0, t\_0, t\_1 \cdot \cos \phi_1\right)\\
\mathbf{if}\;\phi_2 \leq 0.055:\\
\;\;\;\;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}}{\sqrt{1 - t\_2}}\right)\\
\end{array}
\end{array}
if phi2 < 0.0550000000000000003Initial program 71.7%
Applied rewrites71.7%
Applied rewrites71.7%
Taylor expanded in phi2 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6471.6
Applied rewrites71.6%
Taylor expanded in phi2 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6471.8
Applied rewrites71.8%
if 0.0550000000000000003 < phi2 Initial program 51.6%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6451.7
Applied rewrites51.7%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6451.9
Applied rewrites51.9%
Taylor expanded in phi1 around 0
lower-*.f6452.4
Applied rewrites52.4%
Taylor expanded in phi1 around 0
lower-*.f6452.9
Applied rewrites52.9%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (sin (* 0.5 (- phi1 phi2))))
(t_2 (fma t_1 t_1 (* (cos phi2) t_0)))
(t_3 (+ (* t_0 (cos phi1)) (pow (sin (* 0.5 phi1)) 2.0))))
(if (<= phi1 -5.8e-39)
(* R (* 2.0 (atan2 (sqrt t_3) (sqrt (- 1.0 t_3)))))
(* R (* 2.0 (atan2 (sqrt t_2) (sqrt (- 1.0 t_2))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
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 = sin((0.5 * (phi1 - phi2)));
double t_2 = fma(t_1, t_1, (cos(phi2) * t_0));
double t_3 = (t_0 * cos(phi1)) + pow(sin((0.5 * phi1)), 2.0);
double tmp;
if (phi1 <= -5.8e-39) {
tmp = R * (2.0 * atan2(sqrt(t_3), sqrt((1.0 - t_3))));
} else {
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = sin(Float64(0.5 * Float64(phi1 - phi2))) t_2 = fma(t_1, t_1, Float64(cos(phi2) * t_0)) t_3 = Float64(Float64(t_0 * cos(phi1)) + (sin(Float64(0.5 * phi1)) ^ 2.0)) tmp = 0.0 if (phi1 <= -5.8e-39) 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(t_2), sqrt(Float64(1.0 - t_2))))); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t$95$1 + N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -5.8e-39], 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[t$95$2], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\\
t_2 := \mathsf{fma}\left(t\_1, t\_1, \cos \phi_2 \cdot t\_0\right)\\
t_3 := t\_0 \cdot \cos \phi_1 + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\\
\mathbf{if}\;\phi_1 \leq -5.8 \cdot 10^{-39}:\\
\;\;\;\;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}}{\sqrt{1 - t\_2}}\right)\\
\end{array}
\end{array}
if phi1 < -5.79999999999999975e-39Initial program 54.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites52.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites53.4%
lift-cos.f64N/A
lift-fma.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-+.f64N/A
Applied rewrites53.4%
lift-cos.f64N/A
lift-fma.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-+.f64N/A
Applied rewrites53.4%
if -5.79999999999999975e-39 < phi1 Initial program 71.0%
Applied rewrites71.0%
Applied rewrites71.0%
Taylor expanded in phi1 around 0
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6471.1
Applied rewrites71.1%
Taylor expanded in phi1 around 0
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6471.2
Applied rewrites71.2%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (+ (pow (sin (* -0.5 phi2)) 2.0) (* t_0 (cos phi2))))
(t_2 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* t_0 (cos phi1)))))
(if (<= phi2 0.055)
(* R (* 2.0 (atan2 (sqrt t_2) (sqrt (- 1.0 t_2)))))
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = pow(sin((-0.5 * phi2)), 2.0) + (t_0 * cos(phi2));
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * cos(phi1));
double tmp;
if (phi2 <= 0.055) {
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
} else {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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 * (lambda1 - lambda2))) ** 2.0d0
t_1 = (sin(((-0.5d0) * phi2)) ** 2.0d0) + (t_0 * cos(phi2))
t_2 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * cos(phi1))
if (phi2 <= 0.055d0) then
tmp = r * (2.0d0 * atan2(sqrt(t_2), sqrt((1.0d0 - t_2))))
else
tmp = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
end if
code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = Math.pow(Math.sin((-0.5 * phi2)), 2.0) + (t_0 * Math.cos(phi2));
double t_2 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * Math.cos(phi1));
double tmp;
if (phi2 <= 0.055) {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_2), Math.sqrt((1.0 - t_2))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin((0.5 * (lambda1 - lambda2))), 2.0) t_1 = math.pow(math.sin((-0.5 * phi2)), 2.0) + (t_0 * math.cos(phi2)) t_2 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * math.cos(phi1)) tmp = 0 if phi2 <= 0.055: tmp = R * (2.0 * math.atan2(math.sqrt(t_2), math.sqrt((1.0 - t_2)))) else: tmp = R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1)))) return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = Float64((sin(Float64(-0.5 * phi2)) ^ 2.0) + Float64(t_0 * cos(phi2))) t_2 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * cos(phi1))) tmp = 0.0 if (phi2 <= 0.055) 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(t_1), sqrt(Float64(1.0 - t_1))))); end return tmp end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin((0.5 * (lambda1 - lambda2))) ^ 2.0;
t_1 = (sin((-0.5 * phi2)) ^ 2.0) + (t_0 * cos(phi2));
t_2 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * cos(phi1));
tmp = 0.0;
if (phi2 <= 0.055)
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
else
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
end
tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, 0.055], 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[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := {\sin \left(-0.5 \cdot \phi_2\right)}^{2} + t\_0 \cdot \cos \phi_2\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t\_0 \cdot \cos \phi_1\\
\mathbf{if}\;\phi_2 \leq 0.055:\\
\;\;\;\;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}}{\sqrt{1 - t\_1}}\right)\\
\end{array}
\end{array}
if phi2 < 0.0550000000000000003Initial program 71.7%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6471.6
Applied rewrites71.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6471.7
Applied rewrites71.7%
if 0.0550000000000000003 < phi2 Initial program 51.6%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6451.7
Applied rewrites51.7%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6451.9
Applied rewrites51.9%
Taylor expanded in phi1 around 0
lower-*.f6452.4
Applied rewrites52.4%
Taylor expanded in phi1 around 0
lower-*.f6452.9
Applied rewrites52.9%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (+ (pow (sin (* -0.5 phi2)) 2.0) (* t_0 (cos phi2))))
(t_2 (+ (* t_0 (cos phi1)) (pow (sin (* 0.5 phi1)) 2.0))))
(if (<= phi1 -5.8e-39)
(* R (* 2.0 (atan2 (sqrt t_2) (sqrt (- 1.0 t_2)))))
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = pow(sin((-0.5 * phi2)), 2.0) + (t_0 * cos(phi2));
double t_2 = (t_0 * cos(phi1)) + pow(sin((0.5 * phi1)), 2.0);
double tmp;
if (phi1 <= -5.8e-39) {
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
} else {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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 * (lambda1 - lambda2))) ** 2.0d0
t_1 = (sin(((-0.5d0) * phi2)) ** 2.0d0) + (t_0 * cos(phi2))
t_2 = (t_0 * cos(phi1)) + (sin((0.5d0 * phi1)) ** 2.0d0)
if (phi1 <= (-5.8d-39)) then
tmp = r * (2.0d0 * atan2(sqrt(t_2), sqrt((1.0d0 - t_2))))
else
tmp = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
end if
code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = Math.pow(Math.sin((-0.5 * phi2)), 2.0) + (t_0 * Math.cos(phi2));
double t_2 = (t_0 * Math.cos(phi1)) + Math.pow(Math.sin((0.5 * phi1)), 2.0);
double tmp;
if (phi1 <= -5.8e-39) {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_2), Math.sqrt((1.0 - t_2))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin((0.5 * (lambda1 - lambda2))), 2.0) t_1 = math.pow(math.sin((-0.5 * phi2)), 2.0) + (t_0 * math.cos(phi2)) t_2 = (t_0 * math.cos(phi1)) + math.pow(math.sin((0.5 * phi1)), 2.0) tmp = 0 if phi1 <= -5.8e-39: tmp = R * (2.0 * math.atan2(math.sqrt(t_2), math.sqrt((1.0 - t_2)))) else: tmp = R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1)))) return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = Float64((sin(Float64(-0.5 * phi2)) ^ 2.0) + Float64(t_0 * cos(phi2))) t_2 = Float64(Float64(t_0 * cos(phi1)) + (sin(Float64(0.5 * phi1)) ^ 2.0)) tmp = 0.0 if (phi1 <= -5.8e-39) 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(t_1), sqrt(Float64(1.0 - t_1))))); end return tmp end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin((0.5 * (lambda1 - lambda2))) ^ 2.0;
t_1 = (sin((-0.5 * phi2)) ^ 2.0) + (t_0 * cos(phi2));
t_2 = (t_0 * cos(phi1)) + (sin((0.5 * phi1)) ^ 2.0);
tmp = 0.0;
if (phi1 <= -5.8e-39)
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
else
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
end
tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -5.8e-39], 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[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := {\sin \left(-0.5 \cdot \phi_2\right)}^{2} + t\_0 \cdot \cos \phi_2\\
t_2 := t\_0 \cdot \cos \phi_1 + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\\
\mathbf{if}\;\phi_1 \leq -5.8 \cdot 10^{-39}:\\
\;\;\;\;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}}{\sqrt{1 - t\_1}}\right)\\
\end{array}
\end{array}
if phi1 < -5.79999999999999975e-39Initial program 54.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites52.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites53.4%
lift-cos.f64N/A
lift-fma.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-+.f64N/A
Applied rewrites53.4%
lift-cos.f64N/A
lift-fma.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-+.f64N/A
Applied rewrites53.4%
if -5.79999999999999975e-39 < phi1 Initial program 71.0%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6471.1
Applied rewrites71.1%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6471.2
Applied rewrites71.2%
Taylor expanded in phi1 around 0
lower-*.f6469.7
Applied rewrites69.7%
Taylor expanded in phi1 around 0
lower-*.f6469.8
Applied rewrites69.8%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (fma t_0 (cos phi2) (pow (sin (* -0.5 phi2)) 2.0)))
(t_2 (+ (* t_0 (cos phi1)) (pow (sin (* 0.5 phi1)) 2.0))))
(if (<= phi1 -5.8e-39)
(* R (* 2.0 (atan2 (sqrt t_2) (sqrt (- 1.0 t_2)))))
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
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(t_0, cos(phi2), pow(sin((-0.5 * phi2)), 2.0));
double t_2 = (t_0 * cos(phi1)) + pow(sin((0.5 * phi1)), 2.0);
double tmp;
if (phi1 <= -5.8e-39) {
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
} else {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = fma(t_0, cos(phi2), (sin(Float64(-0.5 * phi2)) ^ 2.0)) t_2 = Float64(Float64(t_0 * cos(phi1)) + (sin(Float64(0.5 * phi1)) ^ 2.0)) tmp = 0.0 if (phi1 <= -5.8e-39) 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(t_1), sqrt(Float64(1.0 - t_1))))); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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[(t$95$0 * N[Cos[phi2], $MachinePrecision] + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -5.8e-39], 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[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \mathsf{fma}\left(t\_0, \cos \phi_2, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)\\
t_2 := t\_0 \cdot \cos \phi_1 + {\sin \left(0.5 \cdot \phi_1\right)}^{2}\\
\mathbf{if}\;\phi_1 \leq -5.8 \cdot 10^{-39}:\\
\;\;\;\;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}}{\sqrt{1 - t\_1}}\right)\\
\end{array}
\end{array}
if phi1 < -5.79999999999999975e-39Initial program 54.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites52.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites53.4%
lift-cos.f64N/A
lift-fma.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-+.f64N/A
Applied rewrites53.4%
lift-cos.f64N/A
lift-fma.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-+.f64N/A
Applied rewrites53.4%
if -5.79999999999999975e-39 < phi1 Initial program 71.0%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites69.6%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites69.8%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (fma t_0 (cos phi2) (pow (sin (* -0.5 phi2)) 2.0)))
(t_2 (fma t_0 (cos phi1) (pow (sin (* 0.5 phi1)) 2.0))))
(if (<= phi1 -5.8e-39)
(* R (* 2.0 (atan2 (sqrt t_2) (sqrt (- 1.0 t_2)))))
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
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(t_0, cos(phi2), pow(sin((-0.5 * phi2)), 2.0));
double t_2 = fma(t_0, cos(phi1), pow(sin((0.5 * phi1)), 2.0));
double tmp;
if (phi1 <= -5.8e-39) {
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
} else {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = fma(t_0, cos(phi2), (sin(Float64(-0.5 * phi2)) ^ 2.0)) t_2 = fma(t_0, cos(phi1), (sin(Float64(0.5 * phi1)) ^ 2.0)) tmp = 0.0 if (phi1 <= -5.8e-39) 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(t_1), sqrt(Float64(1.0 - t_1))))); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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[(t$95$0 * N[Cos[phi2], $MachinePrecision] + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * N[Cos[phi1], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -5.8e-39], 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[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \mathsf{fma}\left(t\_0, \cos \phi_2, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)\\
t_2 := \mathsf{fma}\left(t\_0, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
\mathbf{if}\;\phi_1 \leq -5.8 \cdot 10^{-39}:\\
\;\;\;\;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}}{\sqrt{1 - t\_1}}\right)\\
\end{array}
\end{array}
if phi1 < -5.79999999999999975e-39Initial program 54.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites52.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites53.4%
if -5.79999999999999975e-39 < phi1 Initial program 71.0%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites69.6%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites69.8%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(*
(* (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0) (cos phi2))
(cos phi1)))
(t_1 (* 0.5 (- phi1 phi2)))
(t_2 (+ (- 0.5 (* 0.5 (cos (* 2.0 t_1)))) t_0))
(t_3 (sin t_1)))
(*
R
(*
2.0
(atan2
(sqrt (fma t_3 t_3 t_0))
(sqrt (/ (- 1.0 (pow t_2 3.0)) (+ 1.0 (fma t_2 t_2 (* 1.0 t_2))))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (pow(sin((0.5 * (lambda1 - lambda2))), 2.0) * cos(phi2)) * cos(phi1);
double t_1 = 0.5 * (phi1 - phi2);
double t_2 = (0.5 - (0.5 * cos((2.0 * t_1)))) + t_0;
double t_3 = sin(t_1);
return R * (2.0 * atan2(sqrt(fma(t_3, t_3, t_0)), sqrt(((1.0 - pow(t_2, 3.0)) / (1.0 + fma(t_2, t_2, (1.0 * t_2)))))));
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64((sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0) * cos(phi2)) * cos(phi1)) t_1 = Float64(0.5 * Float64(phi1 - phi2)) t_2 = Float64(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * t_1)))) + t_0) t_3 = sin(t_1) return Float64(R * Float64(2.0 * atan(sqrt(fma(t_3, t_3, t_0)), sqrt(Float64(Float64(1.0 - (t_2 ^ 3.0)) / Float64(1.0 + fma(t_2, t_2, Float64(1.0 * t_2)))))))) end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]}, Block[{t$95$3 = N[Sin[t$95$1], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$3 * t$95$3 + t$95$0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Power[t$95$2, 3.0], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(t$95$2 * t$95$2 + N[(1.0 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2\right) \cdot \cos \phi_1\\
t_1 := 0.5 \cdot \left(\phi_1 - \phi_2\right)\\
t_2 := \left(0.5 - 0.5 \cdot \cos \left(2 \cdot t\_1\right)\right) + t\_0\\
t_3 := \sin t\_1\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_3, t\_3, t\_0\right)}}{\sqrt{\frac{1 - {t\_2}^{3}}{1 + \mathsf{fma}\left(t\_2, t\_2, 1 \cdot t\_2\right)}}}\right)
\end{array}
\end{array}
Initial program 62.7%
Applied rewrites62.7%
Applied rewrites62.7%
Applied rewrites62.8%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* 0.5 (- phi1 phi2))))
(t_1
(fma
t_0
t_0
(*
(* (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0) (cos phi2))
(cos phi1)))))
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin((0.5 * (phi1 - phi2)));
double t_1 = fma(t_0, t_0, ((pow(sin((0.5 * (lambda1 - lambda2))), 2.0) * cos(phi2)) * cos(phi1)));
return R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(phi1 - phi2))) t_1 = fma(t_0, t_0, Float64(Float64((sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0) * cos(phi2)) * cos(phi1))) return Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * t$95$0 + N[(N[(N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $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}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\\
t_1 := \mathsf{fma}\left(t\_0, t\_0, \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)
\end{array}
\end{array}
Initial program 62.7%
Applied rewrites62.7%
Applied rewrites62.7%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0))))
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_0) t_0)))
(sqrt
(-
(-
1.0
(*
(* (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0) (cos phi2))
(cos phi1)))
(pow (sin (* 0.5 (- phi1 phi2))) 2.0))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt(((1.0 - ((pow(sin((0.5 * (lambda1 - lambda2))), 2.0) * cos(phi2)) * cos(phi1))) - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt(((1.0d0 - (((sin((0.5d0 * (lambda1 - lambda2))) ** 2.0d0) * cos(phi2)) * cos(phi1))) - (sin((0.5d0 * (phi1 - phi2))) ** 2.0d0)))))
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((Math.cos(phi1) * Math.cos(phi2)) * t_0) * t_0))), Math.sqrt(((1.0 - ((Math.pow(Math.sin((0.5 * (lambda1 - lambda2))), 2.0) * Math.cos(phi2)) * Math.cos(phi1))) - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((math.cos(phi1) * math.cos(phi2)) * t_0) * t_0))), math.sqrt(((1.0 - ((math.pow(math.sin((0.5 * (lambda1 - lambda2))), 2.0) * math.cos(phi2)) * math.cos(phi1))) - math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)))))
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt(Float64(Float64(1.0 - Float64(Float64((sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0) * cos(phi2)) * cos(phi1))) - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0)))))) end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) / 2.0));
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0))), sqrt(((1.0 - (((sin((0.5 * (lambda1 - lambda2))) ^ 2.0) * cos(phi2)) * cos(phi1))) - (sin((0.5 * (phi1 - phi2))) ^ 2.0)))));
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[(N[(N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot t\_0}}{\sqrt{\left(1 - \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2\right) \cdot \cos \phi_1\right) - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)
\end{array}
\end{array}
Initial program 62.7%
Applied rewrites62.7%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1
(+
(- 0.5 (* 0.5 (cos (* 2.0 (* 0.5 (- phi1 phi2))))))
(* t_0 (cos phi2))))
(t_2 (fma t_0 (cos phi1) (pow (sin (* 0.5 phi1)) 2.0))))
(if (<= phi2 5.4e-15)
(* R (* 2.0 (atan2 (sqrt t_2) (sqrt (- 1.0 t_2)))))
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
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 = (0.5 - (0.5 * cos((2.0 * (0.5 * (phi1 - phi2)))))) + (t_0 * cos(phi2));
double t_2 = fma(t_0, cos(phi1), pow(sin((0.5 * phi1)), 2.0));
double tmp;
if (phi2 <= 5.4e-15) {
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
} else {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = Float64(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * Float64(0.5 * Float64(phi1 - phi2)))))) + Float64(t_0 * cos(phi2))) t_2 = fma(t_0, cos(phi1), (sin(Float64(0.5 * phi1)) ^ 2.0)) tmp = 0.0 if (phi2 <= 5.4e-15) 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(t_1), sqrt(Float64(1.0 - t_1))))); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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[(0.5 - N[(0.5 * N[Cos[N[(2.0 * N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * N[Cos[phi1], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, 5.4e-15], 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[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \left(0.5 - 0.5 \cdot \cos \left(2 \cdot \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right)\right) + t\_0 \cdot \cos \phi_2\\
t_2 := \mathsf{fma}\left(t\_0, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
\mathbf{if}\;\phi_2 \leq 5.4 \cdot 10^{-15}:\\
\;\;\;\;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}}{\sqrt{1 - t\_1}}\right)\\
\end{array}
\end{array}
if phi2 < 5.40000000000000018e-15Initial program 71.7%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites69.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites69.8%
if 5.40000000000000018e-15 < phi2 Initial program 52.3%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6452.3
Applied rewrites52.3%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6452.3
Applied rewrites52.3%
Taylor expanded in phi1 around inf
pow2N/A
sqr-sin-aN/A
lower--.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f6451.9
Applied rewrites51.9%
Taylor expanded in phi1 around inf
pow2N/A
sqr-sin-aN/A
lower--.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f6451.9
Applied rewrites51.9%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(+
(- 0.5 (* 0.5 (cos (* 2.0 (* 0.5 (- phi1 phi2))))))
(* (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0) (cos phi2))))
(t_1
(fma
(pow (sin (* -0.5 lambda2)) 2.0)
(cos phi1)
(pow (sin (* 0.5 phi1)) 2.0))))
(if (<= phi1 -1.22e-5)
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))
(* R (* 2.0 (atan2 (sqrt t_0) (sqrt (- 1.0 t_0))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (0.5 - (0.5 * cos((2.0 * (0.5 * (phi1 - phi2)))))) + (pow(sin((0.5 * (lambda1 - lambda2))), 2.0) * cos(phi2));
double t_1 = fma(pow(sin((-0.5 * lambda2)), 2.0), cos(phi1), pow(sin((0.5 * phi1)), 2.0));
double tmp;
if (phi1 <= -1.22e-5) {
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;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * Float64(0.5 * Float64(phi1 - phi2)))))) + Float64((sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0) * cos(phi2))) t_1 = fma((sin(Float64(-0.5 * lambda2)) ^ 2.0), cos(phi1), (sin(Float64(0.5 * phi1)) ^ 2.0)) tmp = 0.0 if (phi1 <= -1.22e-5) 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
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[Sin[N[(0.5 * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[Sin[N[(-0.5 * lambda2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -1.22e-5], 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}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \left(0.5 - 0.5 \cdot \cos \left(2 \cdot \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right)\right) + {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_2\\
t_1 := \mathsf{fma}\left({\sin \left(-0.5 \cdot \lambda_2\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
\mathbf{if}\;\phi_1 \leq -1.22 \cdot 10^{-5}:\\
\;\;\;\;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 phi1 < -1.22000000000000001e-5Initial program 51.5%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites52.2%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites52.9%
Taylor expanded in lambda1 around 0
lift-*.f6442.0
Applied rewrites42.0%
Taylor expanded in lambda1 around 0
lift-*.f6441.6
Applied rewrites41.6%
if -1.22000000000000001e-5 < phi1 Initial program 71.7%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6471.8
Applied rewrites71.8%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6471.9
Applied rewrites71.9%
Taylor expanded in phi1 around inf
pow2N/A
sqr-sin-aN/A
lower--.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f6467.2
Applied rewrites67.2%
Taylor expanded in phi1 around inf
pow2N/A
sqr-sin-aN/A
lower--.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f6467.2
Applied rewrites67.2%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1
(+
(- 0.5 (* 0.5 (cos (* 2.0 (* 0.5 (- phi1 phi2))))))
(* t_0 (cos phi2))))
(t_2 (sin (/ (- lambda1 lambda2) 2.0)))
(t_3 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(t_4 (+ t_3 t_0))
(t_5 (+ t_3 (* (* (* (cos phi1) (cos phi2)) t_2) t_2))))
(if (<= (* 2.0 (atan2 (sqrt t_5) (sqrt (- 1.0 t_5)))) 0.1)
(* R (* 2.0 (atan2 (sqrt t_4) (sqrt (- 1.0 t_4)))))
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
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 = (0.5 - (0.5 * cos((2.0 * (0.5 * (phi1 - phi2)))))) + (t_0 * cos(phi2));
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double t_3 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double t_4 = t_3 + t_0;
double t_5 = t_3 + (((cos(phi1) * cos(phi2)) * t_2) * t_2);
double tmp;
if ((2.0 * atan2(sqrt(t_5), sqrt((1.0 - t_5)))) <= 0.1) {
tmp = R * (2.0 * atan2(sqrt(t_4), sqrt((1.0 - t_4))));
} else {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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) :: t_5
real(8) :: tmp
t_0 = sin((0.5d0 * (lambda1 - lambda2))) ** 2.0d0
t_1 = (0.5d0 - (0.5d0 * cos((2.0d0 * (0.5d0 * (phi1 - phi2)))))) + (t_0 * cos(phi2))
t_2 = sin(((lambda1 - lambda2) / 2.0d0))
t_3 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
t_4 = t_3 + t_0
t_5 = t_3 + (((cos(phi1) * cos(phi2)) * t_2) * t_2)
if ((2.0d0 * atan2(sqrt(t_5), sqrt((1.0d0 - t_5)))) <= 0.1d0) then
tmp = r * (2.0d0 * atan2(sqrt(t_4), sqrt((1.0d0 - t_4))))
else
tmp = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
end if
code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin((0.5 * (lambda1 - lambda2))), 2.0);
double t_1 = (0.5 - (0.5 * Math.cos((2.0 * (0.5 * (phi1 - phi2)))))) + (t_0 * Math.cos(phi2));
double t_2 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_3 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0);
double t_4 = t_3 + t_0;
double t_5 = t_3 + (((Math.cos(phi1) * Math.cos(phi2)) * t_2) * t_2);
double tmp;
if ((2.0 * Math.atan2(Math.sqrt(t_5), Math.sqrt((1.0 - t_5)))) <= 0.1) {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_4), Math.sqrt((1.0 - t_4))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin((0.5 * (lambda1 - lambda2))), 2.0) t_1 = (0.5 - (0.5 * math.cos((2.0 * (0.5 * (phi1 - phi2)))))) + (t_0 * math.cos(phi2)) t_2 = math.sin(((lambda1 - lambda2) / 2.0)) t_3 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) t_4 = t_3 + t_0 t_5 = t_3 + (((math.cos(phi1) * math.cos(phi2)) * t_2) * t_2) tmp = 0 if (2.0 * math.atan2(math.sqrt(t_5), math.sqrt((1.0 - t_5)))) <= 0.1: tmp = R * (2.0 * math.atan2(math.sqrt(t_4), math.sqrt((1.0 - t_4)))) else: tmp = R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1)))) return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = Float64(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * Float64(0.5 * Float64(phi1 - phi2)))))) + Float64(t_0 * cos(phi2))) t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_3 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 t_4 = Float64(t_3 + t_0) t_5 = Float64(t_3 + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_2) * t_2)) tmp = 0.0 if (Float64(2.0 * atan(sqrt(t_5), sqrt(Float64(1.0 - t_5)))) <= 0.1) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_4), sqrt(Float64(1.0 - t_4))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))); end return tmp end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin((0.5 * (lambda1 - lambda2))) ^ 2.0;
t_1 = (0.5 - (0.5 * cos((2.0 * (0.5 * (phi1 - phi2)))))) + (t_0 * cos(phi2));
t_2 = sin(((lambda1 - lambda2) / 2.0));
t_3 = sin(((phi1 - phi2) / 2.0)) ^ 2.0;
t_4 = t_3 + t_0;
t_5 = t_3 + (((cos(phi1) * cos(phi2)) * t_2) * t_2);
tmp = 0.0;
if ((2.0 * atan2(sqrt(t_5), sqrt((1.0 - t_5)))) <= 0.1)
tmp = R * (2.0 * atan2(sqrt(t_4), sqrt((1.0 - t_4))));
else
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
end
tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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[(0.5 - N[(0.5 * N[Cos[N[(2.0 * N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $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$0), $MachinePrecision]}, Block[{t$95$5 = N[(t$95$3 + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(2.0 * N[ArcTan[N[Sqrt[t$95$5], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.1], 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[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \left(0.5 - 0.5 \cdot \cos \left(2 \cdot \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right)\right) + t\_0 \cdot \cos \phi_2\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_4 := t\_3 + t\_0\\
t_5 := t\_3 + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t\_2\right) \cdot t\_2\\
\mathbf{if}\;2 \cdot \tan^{-1}_* \frac{\sqrt{t\_5}}{\sqrt{1 - t\_5}} \leq 0.1:\\
\;\;\;\;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{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))))))))) < 0.10000000000000001Initial program 91.5%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6491.5
Applied rewrites91.5%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6491.5
Applied rewrites91.5%
Taylor expanded in phi2 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6491.2
Applied rewrites91.2%
Taylor expanded in phi2 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6491.1
Applied rewrites91.1%
if 0.10000000000000001 < (*.f64 #s(literal 2 binary64) (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))))))))) Initial program 60.3%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6450.2
Applied rewrites50.2%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6447.8
Applied rewrites47.8%
Taylor expanded in phi1 around inf
pow2N/A
sqr-sin-aN/A
lower--.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f6447.8
Applied rewrites47.8%
Taylor expanded in phi1 around inf
pow2N/A
sqr-sin-aN/A
lower--.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f6447.8
Applied rewrites47.8%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_0))
(t_3
(*
R
(*
2.0
(atan2
(sqrt t_0)
(sqrt
(- 1.0 (fma (cos phi2) t_0 (pow (sin (* -0.5 phi2)) 2.0)))))))))
(if (<= t_1 -0.28)
t_3
(if (<= t_1 0.325)
(* R (* 2.0 (atan2 (sqrt t_2) (sqrt (- 1.0 t_2)))))
t_3))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
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 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_0;
double t_3 = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - fma(cos(phi2), t_0, pow(sin((-0.5 * phi2)), 2.0))))));
double tmp;
if (t_1 <= -0.28) {
tmp = t_3;
} else if (t_1 <= 0.325) {
tmp = R * (2.0 * atan2(sqrt(t_2), sqrt((1.0 - t_2))));
} else {
tmp = t_3;
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_0) t_3 = Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - fma(cos(phi2), t_0, (sin(Float64(-0.5 * phi2)) ^ 2.0))))))) tmp = 0.0 if (t_1 <= -0.28) tmp = t_3; elseif (t_1 <= 0.325) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_2), sqrt(Float64(1.0 - t_2))))); else tmp = t_3; end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$0), $MachinePrecision]}, Block[{t$95$3 = N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$0], $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]}, If[LessEqual[t$95$1, -0.28], t$95$3, If[LessEqual[t$95$1, 0.325], 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}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t\_0\\
t_3 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - \mathsf{fma}\left(\cos \phi_2, t\_0, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}\right)\\
\mathbf{if}\;t\_1 \leq -0.28:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_1 \leq 0.325:\\
\;\;\;\;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.28000000000000003 or 0.325000000000000011 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) Initial program 57.3%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites45.7%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites46.0%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6433.7
Applied rewrites33.7%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6433.2
Applied rewrites33.2%
Taylor expanded in phi1 around 0
lower--.f64N/A
lower-fma.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lift-*.f6433.7
Applied rewrites33.7%
if -0.28000000000000003 < (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))) < 0.325000000000000011Initial program 71.1%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6466.6
Applied rewrites66.6%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f6466.3
Applied rewrites66.3%
Taylor expanded in phi2 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6461.3
Applied rewrites61.3%
Taylor expanded in phi2 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6460.8
Applied rewrites60.8%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (/ (- lambda1 lambda2) 2.0))
(t_2 (sin t_1))
(t_3
(*
R
(*
2.0
(atan2
(sqrt (fma (cos phi2) t_0 (pow (sin (* -0.5 phi2)) 2.0)))
(sqrt (- 1.0 t_0)))))))
(if (<= t_1 -1e-30)
t_3
(if (<= t_1 2e-103)
(*
R
(*
2.0
(atan2
(sqrt (- 0.5 (* 0.5 (cos (* 2.0 (* 0.5 (- phi1 phi2)))))))
(sqrt
(-
1.0
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) 1.0) t_2) t_2)))))))
t_3))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
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 = (lambda1 - lambda2) / 2.0;
double t_2 = sin(t_1);
double t_3 = R * (2.0 * atan2(sqrt(fma(cos(phi2), t_0, pow(sin((-0.5 * phi2)), 2.0))), sqrt((1.0 - t_0))));
double tmp;
if (t_1 <= -1e-30) {
tmp = t_3;
} else if (t_1 <= 2e-103) {
tmp = R * (2.0 * atan2(sqrt((0.5 - (0.5 * cos((2.0 * (0.5 * (phi1 - phi2))))))), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * 1.0) * t_2) * t_2))))));
} else {
tmp = t_3;
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = Float64(Float64(lambda1 - lambda2) / 2.0) t_2 = sin(t_1) t_3 = Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi2), t_0, (sin(Float64(-0.5 * phi2)) ^ 2.0))), sqrt(Float64(1.0 - t_0))))) tmp = 0.0 if (t_1 <= -1e-30) tmp = t_3; elseif (t_1 <= 2e-103) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * Float64(0.5 * Float64(phi1 - phi2))))))), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * 1.0) * t_2) * t_2))))))); else tmp = t_3; end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]}, Block[{t$95$2 = N[Sin[t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi2], $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-30], t$95$3, If[LessEqual[t$95$1, 2e-103], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $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[(N[(N[Cos[phi1], $MachinePrecision] * 1.0), $MachinePrecision] * t$95$2), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \frac{\lambda_1 - \lambda_2}{2}\\
t_2 := \sin t\_1\\
t_3 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_2, t\_0, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}{\sqrt{1 - t\_0}}\right)\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-30}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-103}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{0.5 - 0.5 \cdot \cos \left(2 \cdot \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)\right)}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot 1\right) \cdot t\_2\right) \cdot t\_2\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)) < -1e-30 or 1.99999999999999992e-103 < (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)) Initial program 60.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites46.3%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites46.4%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6432.3
Applied rewrites32.3%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6431.9
Applied rewrites31.9%
Taylor expanded in phi1 around 0
lower-sqrt.f64N/A
lower-fma.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lift-*.f6433.4
Applied rewrites33.4%
if -1e-30 < (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)) < 1.99999999999999992e-103Initial program 77.2%
Taylor expanded in lambda1 around 0
lower-sqrt.f64N/A
lower-fma.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lift-cos.f64N/A
Applied rewrites73.7%
Taylor expanded in phi2 around 0
Applied rewrites73.7%
Taylor expanded in phi2 around 0
Applied rewrites73.7%
Taylor expanded in lambda2 around 0
pow2N/A
sqr-sin-a-revN/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift--.f6456.5
Applied rewrites56.5%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (fma t_0 1.0 (pow (sin (* 0.5 phi1)) 2.0))))
(if (<= phi2 1.35e-49)
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))
(*
R
(*
2.0
(atan2
(sqrt (fma (cos phi2) t_0 (pow (sin (* -0.5 phi2)) 2.0)))
(sqrt (- 1.0 t_0))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
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(t_0, 1.0, pow(sin((0.5 * phi1)), 2.0));
double tmp;
if (phi2 <= 1.35e-49) {
tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
} else {
tmp = R * (2.0 * atan2(sqrt(fma(cos(phi2), t_0, pow(sin((-0.5 * phi2)), 2.0))), sqrt((1.0 - t_0))));
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = fma(t_0, 1.0, (sin(Float64(0.5 * phi1)) ^ 2.0)) tmp = 0.0 if (phi2 <= 1.35e-49) 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(fma(cos(phi2), t_0, (sin(Float64(-0.5 * phi2)) ^ 2.0))), sqrt(Float64(1.0 - t_0))))); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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[(t$95$0 * 1.0 + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, 1.35e-49], 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[N[(N[Cos[phi2], $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \mathsf{fma}\left(t\_0, 1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)\\
\mathbf{if}\;\phi_2 \leq 1.35 \cdot 10^{-49}:\\
\;\;\;\;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{\mathsf{fma}\left(\cos \phi_2, t\_0, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}{\sqrt{1 - t\_0}}\right)\\
\end{array}
\end{array}
if phi2 < 1.35e-49Initial program 70.9%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites69.7%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites69.9%
Taylor expanded in phi1 around 0
Applied rewrites52.6%
Taylor expanded in phi1 around 0
Applied rewrites47.7%
if 1.35e-49 < phi2 Initial program 54.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites23.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites23.6%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6420.3
Applied rewrites20.3%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6420.2
Applied rewrites20.2%
Taylor expanded in phi1 around 0
lower-sqrt.f64N/A
lower-fma.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lift-*.f6425.6
Applied rewrites25.6%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))
(t_1 (sqrt (- 1.0 t_0))))
(if (<= phi1 -3e-68)
(*
R
(*
2.0
(atan2 (sqrt (fma (cos phi1) t_0 (pow (sin (* 0.5 phi1)) 2.0))) t_1)))
(*
R
(*
2.0
(atan2
(sqrt (fma (cos phi2) t_0 (pow (sin (* -0.5 phi2)) 2.0)))
t_1))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
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 = sqrt((1.0 - t_0));
double tmp;
if (phi1 <= -3e-68) {
tmp = R * (2.0 * atan2(sqrt(fma(cos(phi1), t_0, pow(sin((0.5 * phi1)), 2.0))), t_1));
} else {
tmp = R * (2.0 * atan2(sqrt(fma(cos(phi2), t_0, pow(sin((-0.5 * phi2)), 2.0))), t_1));
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 t_1 = sqrt(Float64(1.0 - t_0)) tmp = 0.0 if (phi1 <= -3e-68) tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi1), t_0, (sin(Float64(0.5 * phi1)) ^ 2.0))), t_1))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi2), t_0, (sin(Float64(-0.5 * phi2)) ^ 2.0))), t_1))); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -3e-68], 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] / t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Cos[phi2], $MachinePrecision] * t$95$0 + N[Power[N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
t_1 := \sqrt{1 - t\_0}\\
\mathbf{if}\;\phi_1 \leq -3 \cdot 10^{-68}:\\
\;\;\;\;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)}}{t\_1}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_2, t\_0, {\sin \left(-0.5 \cdot \phi_2\right)}^{2}\right)}}{t\_1}\right)\\
\end{array}
\end{array}
if phi1 < -3e-68Initial program 55.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites52.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites53.3%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6421.4
Applied rewrites21.4%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6420.7
Applied rewrites20.7%
Taylor expanded in phi2 around 0
lower-sqrt.f64N/A
lower-fma.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift-pow.f6426.3
Applied rewrites26.3%
if -3e-68 < phi1 Initial program 70.4%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites39.9%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites39.5%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6438.3
Applied rewrites38.3%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6438.3
Applied rewrites38.3%
Taylor expanded in phi1 around 0
lower-sqrt.f64N/A
lower-fma.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lift-*.f6443.8
Applied rewrites43.8%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0)))
(*
R
(*
2.0
(atan2
(sqrt (fma (cos phi1) t_0 (pow (sin (* 0.5 phi1)) 2.0)))
(sqrt (- 1.0 t_0)))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
return R * (2.0 * atan2(sqrt(fma(cos(phi1), t_0, pow(sin((0.5 * phi1)), 2.0))), sqrt((1.0 - t_0))));
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 return Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi1), t_0, (sin(Float64(0.5 * phi1)) ^ 2.0))), sqrt(Float64(1.0 - t_0))))) end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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]}, 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 - t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
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 - t\_0}}\right)
\end{array}
\end{array}
Initial program 62.7%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites46.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites46.7%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6429.5
Applied rewrites29.5%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6429.2
Applied rewrites29.2%
Taylor expanded in phi2 around 0
lower-sqrt.f64N/A
lower-fma.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift-pow.f6432.7
Applied rewrites32.7%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0)))
(if (<= phi1 -1.2e-5)
(*
R
(*
2.0
(atan2
(sqrt (fma (cos phi1) t_0 (pow (sin (* 0.5 phi1)) 2.0)))
(sqrt (- 1.0 (pow (sin (* -0.5 lambda2)) 2.0))))))
(* R (* 2.0 (atan2 (sqrt t_0) (sqrt (- 1.0 t_0))))))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
double tmp;
if (phi1 <= -1.2e-5) {
tmp = R * (2.0 * atan2(sqrt(fma(cos(phi1), t_0, pow(sin((0.5 * phi1)), 2.0))), sqrt((1.0 - pow(sin((-0.5 * lambda2)), 2.0)))));
} else {
tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 tmp = 0.0 if (phi1 <= -1.2e-5) tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(cos(phi1), t_0, (sin(Float64(0.5 * phi1)) ^ 2.0))), sqrt(Float64(1.0 - (sin(Float64(-0.5 * lambda2)) ^ 2.0)))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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]}, If[LessEqual[phi1, -1.2e-5], 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[Power[N[Sin[N[(-0.5 * lambda2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $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}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2}\\
\mathbf{if}\;\phi_1 \leq -1.2 \cdot 10^{-5}:\\
\;\;\;\;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 - {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_0}}{\sqrt{1 - t\_0}}\right)\\
\end{array}
\end{array}
if phi1 < -1.2e-5Initial program 51.5%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites52.2%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites52.9%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6417.7
Applied rewrites17.7%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6417.0
Applied rewrites17.0%
Taylor expanded in lambda1 around 0
lift-*.f6412.8
Applied rewrites12.8%
Taylor expanded in lambda1 around 0
lift-*.f6412.8
Applied rewrites12.8%
Taylor expanded in phi2 around 0
lower-sqrt.f64N/A
lower-fma.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift-pow.f6421.2
Applied rewrites21.2%
if -1.2e-5 < phi1 Initial program 71.7%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites42.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites41.7%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6439.0
Applied rewrites39.0%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6439.0
Applied rewrites39.0%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (let* ((t_0 (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0))) (* R (* 2.0 (atan2 (sqrt t_0) (sqrt (- 1.0 t_0)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * (lambda1 - lambda2))), 2.0);
return R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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 * (lambda1 - lambda2))) ** 2.0d0
code = r * (2.0d0 * atan2(sqrt(t_0), sqrt((1.0d0 - t_0))))
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin((0.5 * (lambda1 - lambda2))), 2.0);
return R * (2.0 * Math.atan2(Math.sqrt(t_0), Math.sqrt((1.0 - t_0))));
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin((0.5 * (lambda1 - lambda2))), 2.0) return R * (2.0 * math.atan2(math.sqrt(t_0), math.sqrt((1.0 - t_0))))
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * Float64(lambda1 - lambda2))) ^ 2.0 return Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))) end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin((0.5 * (lambda1 - lambda2))) ^ 2.0;
tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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]}, 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}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_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 62.7%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites46.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites46.7%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6429.5
Applied rewrites29.5%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6429.2
Applied rewrites29.2%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* 0.5 lambda1)) 2.0))
(t_1 (pow (sin (* -0.5 lambda2)) 2.0))
(t_2 (* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
(if (<= lambda2 -4.5e-9)
t_2
(if (<= lambda2 9.5e-35)
(* R (* 2.0 (atan2 (sqrt t_0) (sqrt (- 1.0 t_0)))))
t_2))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((0.5 * lambda1)), 2.0);
double t_1 = pow(sin((-0.5 * lambda2)), 2.0);
double t_2 = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
double tmp;
if (lambda2 <= -4.5e-9) {
tmp = t_2;
} else if (lambda2 <= 9.5e-35) {
tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
} else {
tmp = t_2;
}
return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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 * lambda1)) ** 2.0d0
t_1 = sin(((-0.5d0) * lambda2)) ** 2.0d0
t_2 = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
if (lambda2 <= (-4.5d-9)) then
tmp = t_2
else if (lambda2 <= 9.5d-35) then
tmp = r * (2.0d0 * atan2(sqrt(t_0), sqrt((1.0d0 - t_0))))
else
tmp = t_2
end if
code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin((0.5 * lambda1)), 2.0);
double t_1 = Math.pow(Math.sin((-0.5 * lambda2)), 2.0);
double t_2 = R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
double tmp;
if (lambda2 <= -4.5e-9) {
tmp = t_2;
} else if (lambda2 <= 9.5e-35) {
tmp = R * (2.0 * Math.atan2(Math.sqrt(t_0), Math.sqrt((1.0 - t_0))));
} else {
tmp = t_2;
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin((0.5 * lambda1)), 2.0) t_1 = math.pow(math.sin((-0.5 * lambda2)), 2.0) t_2 = R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1)))) tmp = 0 if lambda2 <= -4.5e-9: tmp = t_2 elif lambda2 <= 9.5e-35: tmp = R * (2.0 * math.atan2(math.sqrt(t_0), math.sqrt((1.0 - t_0)))) else: tmp = t_2 return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(0.5 * lambda1)) ^ 2.0 t_1 = sin(Float64(-0.5 * lambda2)) ^ 2.0 t_2 = Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) tmp = 0.0 if (lambda2 <= -4.5e-9) tmp = t_2; elseif (lambda2 <= 9.5e-35) tmp = Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))); else tmp = t_2; end return tmp end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin((0.5 * lambda1)) ^ 2.0;
t_1 = sin((-0.5 * lambda2)) ^ 2.0;
t_2 = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
tmp = 0.0;
if (lambda2 <= -4.5e-9)
tmp = t_2;
elseif (lambda2 <= 9.5e-35)
tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
else
tmp = t_2;
end
tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(0.5 * lambda1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(-0.5 * lambda2), $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[lambda2, -4.5e-9], t$95$2, If[LessEqual[lambda2, 9.5e-35], 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}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(0.5 \cdot \lambda_1\right)}^{2}\\
t_1 := {\sin \left(-0.5 \cdot \lambda_2\right)}^{2}\\
t_2 := R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}}\right)\\
\mathbf{if}\;\lambda_2 \leq -4.5 \cdot 10^{-9}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\lambda_2 \leq 9.5 \cdot 10^{-35}:\\
\;\;\;\;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 < -4.49999999999999976e-9 or 9.5000000000000003e-35 < lambda2 Initial program 49.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites39.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites40.0%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6429.9
Applied rewrites29.9%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6429.5
Applied rewrites29.5%
Taylor expanded in lambda1 around 0
lift-*.f6428.5
Applied rewrites28.5%
Taylor expanded in lambda1 around 0
lift-*.f6428.4
Applied rewrites28.4%
if -4.49999999999999976e-9 < lambda2 < 9.5000000000000003e-35Initial program 77.2%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites54.1%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites54.1%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6429.1
Applied rewrites29.1%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6428.9
Applied rewrites28.9%
Taylor expanded in lambda1 around inf
Applied rewrites26.2%
Taylor expanded in lambda1 around inf
Applied rewrites26.2%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (let* ((t_0 (pow (sin (* -0.5 lambda2)) 2.0))) (* R (* 2.0 (atan2 (sqrt t_0) (sqrt (- 1.0 t_0)))))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin((-0.5 * lambda2)), 2.0);
return R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
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) * lambda2)) ** 2.0d0
code = r * (2.0d0 * atan2(sqrt(t_0), sqrt((1.0d0 - t_0))))
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin((-0.5 * lambda2)), 2.0);
return R * (2.0 * Math.atan2(Math.sqrt(t_0), Math.sqrt((1.0 - t_0))));
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin((-0.5 * lambda2)), 2.0) return R * (2.0 * math.atan2(math.sqrt(t_0), math.sqrt((1.0 - t_0))))
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(-0.5 * lambda2)) ^ 2.0 return Float64(R * Float64(2.0 * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0))))) end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin((-0.5 * lambda2)) ^ 2.0;
tmp = R * (2.0 * atan2(sqrt(t_0), sqrt((1.0 - t_0))));
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(-0.5 * lambda2), $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}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(-0.5 \cdot \lambda_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 62.7%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites46.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flipN/A
lower-pow.f64N/A
lower-sin.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
Applied rewrites46.7%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6429.5
Applied rewrites29.5%
Taylor expanded in phi1 around 0
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-pow.f6429.2
Applied rewrites29.2%
Taylor expanded in lambda1 around 0
lift-*.f6419.2
Applied rewrites19.2%
Taylor expanded in lambda1 around 0
lift-*.f6419.1
Applied rewrites19.1%
herbie shell --seed 2025128
(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))))))))))