
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(acos
(+
(* (sin phi1) (sin phi2))
(* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
}
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
code = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * r
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + ((Math.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2))))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.acos(((math.sin(phi1) * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2))))) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))))) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 24 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(acos
(+
(* (sin phi1) (sin phi2))
(* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
}
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
code = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * r
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + ((Math.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2))))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.acos(((math.sin(phi1) * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2))))) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))))) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\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
(*
(acos
(fma
(* (cos phi2) (cos phi1))
(* (cos lambda1) (cos lambda2))
(fma
(* (* (sin lambda1) (sin lambda2)) (cos phi2))
(cos phi1)
(* (sin phi2) (sin phi1)))))
R))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(fma((cos(phi2) * cos(phi1)), (cos(lambda1) * cos(lambda2)), fma(((sin(lambda1) * sin(lambda2)) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1))))) * R;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(fma(Float64(cos(phi2) * cos(phi1)), Float64(cos(lambda1) * cos(lambda2)), fma(Float64(Float64(sin(lambda1) * sin(lambda2)) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1))))) * R) end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, \cos \lambda_1 \cdot \cos \lambda_2, \mathsf{fma}\left(\left(\sin \lambda_1 \cdot \sin \lambda_2\right) \cdot \cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right) \cdot R
\end{array}
Initial program 71.3%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
cos-negN/A
mul-1-negN/A
lower-+.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-cos.f64N/A
cos-negN/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6495.3
Applied rewrites95.3%
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
distribute-lft-inN/A
lower-fma.f64N/A
Applied rewrites95.3%
Applied rewrites95.3%
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
(*
(acos
(+
(* (sin phi1) (sin phi2))
(*
(* (cos phi1) (cos phi2))
(+ (* (cos lambda1) (cos lambda2)) (* (sin lambda1) (sin lambda2))))))
R))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2)))))) * R;
}
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
code = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2)))))) * r
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) {
return Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + ((Math.cos(phi1) * Math.cos(phi2)) * ((Math.cos(lambda1) * Math.cos(lambda2)) + (Math.sin(lambda1) * Math.sin(lambda2)))))) * R;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): return math.acos(((math.sin(phi1) * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * ((math.cos(lambda1) * math.cos(lambda2)) + (math.sin(lambda1) * math.sin(lambda2)))))) * R
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2)))))) * R) end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
tmp = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2)))))) * R;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R
\end{array}
Initial program 71.3%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
cos-negN/A
mul-1-negN/A
lower-+.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-cos.f64N/A
cos-negN/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6495.3
Applied rewrites95.3%
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
(*
(acos
(+
(* (sin phi1) (sin phi2))
(*
(* (cos phi1) (cos phi2))
(fma (cos lambda1) (cos lambda2) (* (sin lambda1) (sin lambda2))))))
R))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * fma(cos(lambda1), cos(lambda2), (sin(lambda1) * sin(lambda2)))))) * R;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * fma(cos(lambda1), cos(lambda2), Float64(sin(lambda1) * sin(lambda2)))))) * R) end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R
\end{array}
Initial program 71.3%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
cos-negN/A
lower-fma.f64N/A
lower-cos.f64N/A
cos-negN/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6495.3
Applied rewrites95.3%
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 phi1) (sin phi2))) (t_1 (* (cos lambda1) (cos lambda2))))
(if (<= phi2 -4.8e-6)
(*
(-
(/ PI 2.0)
(asin
(fma
(* (cos (- lambda1 lambda2)) (cos phi2))
(cos phi1)
(* (sin phi2) (sin phi1)))))
R)
(if (<= phi2 2.4e-12)
(*
(acos (+ t_0 (* (cos phi1) (+ t_1 (* (sin lambda1) (sin lambda2))))))
R)
(* (acos (fma (* (cos phi2) (cos phi1)) t_1 t_0)) R)))))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(phi1) * sin(phi2);
double t_1 = cos(lambda1) * cos(lambda2);
double tmp;
if (phi2 <= -4.8e-6) {
tmp = ((((double) M_PI) / 2.0) - asin(fma((cos((lambda1 - lambda2)) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1))))) * R;
} else if (phi2 <= 2.4e-12) {
tmp = acos((t_0 + (cos(phi1) * (t_1 + (sin(lambda1) * sin(lambda2)))))) * R;
} else {
tmp = acos(fma((cos(phi2) * cos(phi1)), t_1, t_0)) * R;
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(sin(phi1) * sin(phi2)) t_1 = Float64(cos(lambda1) * cos(lambda2)) tmp = 0.0 if (phi2 <= -4.8e-6) tmp = Float64(Float64(Float64(pi / 2.0) - asin(fma(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1))))) * R); elseif (phi2 <= 2.4e-12) tmp = Float64(acos(Float64(t_0 + Float64(cos(phi1) * Float64(t_1 + Float64(sin(lambda1) * sin(lambda2)))))) * R); else tmp = Float64(acos(fma(Float64(cos(phi2) * cos(phi1)), t_1, t_0)) * R); 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[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -4.8e-6], N[(N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi2, 2.4e-12], N[(N[ArcCos[N[(t$95$0 + N[(N[Cos[phi1], $MachinePrecision] * N[(t$95$1 + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$1 + t$95$0), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \phi_1 \cdot \sin \phi_2\\
t_1 := \cos \lambda_1 \cdot \cos \lambda_2\\
\mathbf{if}\;\phi_2 \leq -4.8 \cdot 10^{-6}:\\
\;\;\;\;\left(\frac{\pi}{2} - \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right) \cdot R\\
\mathbf{elif}\;\phi_2 \leq 2.4 \cdot 10^{-12}:\\
\;\;\;\;\cos^{-1} \left(t\_0 + \cos \phi_1 \cdot \left(t\_1 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, t\_1, t\_0\right)\right) \cdot R\\
\end{array}
\end{array}
if phi2 < -4.7999999999999998e-6Initial program 75.4%
lift-acos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f64N/A
acos-asinN/A
lower--.f64N/A
Applied rewrites75.5%
if -4.7999999999999998e-6 < phi2 < 2.39999999999999987e-12Initial program 62.8%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
cos-negN/A
mul-1-negN/A
lower-+.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-cos.f64N/A
cos-negN/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6491.8
Applied rewrites91.8%
Taylor expanded in phi2 around 0
sin-+PI/2-revN/A
lift-cos.f6491.7
Applied rewrites91.7%
if 2.39999999999999987e-12 < phi2 Initial program 85.3%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
cos-negN/A
mul-1-negN/A
lower-+.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-cos.f64N/A
cos-negN/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6499.4
Applied rewrites99.4%
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
distribute-lft-inN/A
lower-fma.f64N/A
Applied rewrites99.3%
Applied rewrites99.3%
Taylor expanded in lambda1 around 0
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f6485.5
Applied rewrites85.5%
Final simplification86.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
(if (<= phi2 -4.8e-6)
(*
(-
(/ PI 2.0)
(asin
(fma
(* (cos (- lambda1 lambda2)) (cos phi2))
(cos phi1)
(* (sin phi2) (sin phi1)))))
R)
(if (<= phi2 2.4e-12)
(*
(acos
(fma
(fma (cos lambda1) (cos lambda2) (* (sin lambda1) (sin lambda2)))
(cos phi1)
(* (sin phi1) phi2)))
R)
(*
(acos
(fma
(* (cos phi2) (cos phi1))
(* (cos lambda1) (cos lambda2))
(* (sin phi1) (sin phi2))))
R))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= -4.8e-6) {
tmp = ((((double) M_PI) / 2.0) - asin(fma((cos((lambda1 - lambda2)) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1))))) * R;
} else if (phi2 <= 2.4e-12) {
tmp = acos(fma(fma(cos(lambda1), cos(lambda2), (sin(lambda1) * sin(lambda2))), cos(phi1), (sin(phi1) * phi2))) * R;
} else {
tmp = acos(fma((cos(phi2) * cos(phi1)), (cos(lambda1) * cos(lambda2)), (sin(phi1) * sin(phi2)))) * R;
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= -4.8e-6) tmp = Float64(Float64(Float64(pi / 2.0) - asin(fma(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1))))) * R); elseif (phi2 <= 2.4e-12) tmp = Float64(acos(fma(fma(cos(lambda1), cos(lambda2), Float64(sin(lambda1) * sin(lambda2))), cos(phi1), Float64(sin(phi1) * phi2))) * R); else tmp = Float64(acos(fma(Float64(cos(phi2) * cos(phi1)), Float64(cos(lambda1) * cos(lambda2)), Float64(sin(phi1) * sin(phi2)))) * R); 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_] := If[LessEqual[phi2, -4.8e-6], N[(N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi2, 2.4e-12], N[(N[ArcCos[N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq -4.8 \cdot 10^{-6}:\\
\;\;\;\;\left(\frac{\pi}{2} - \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right) \cdot R\\
\mathbf{elif}\;\phi_2 \leq 2.4 \cdot 10^{-12}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right), \cos \phi_1, \sin \phi_1 \cdot \phi_2\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, \cos \lambda_1 \cdot \cos \lambda_2, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R\\
\end{array}
\end{array}
if phi2 < -4.7999999999999998e-6Initial program 75.4%
lift-acos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f64N/A
acos-asinN/A
lower--.f64N/A
Applied rewrites75.5%
if -4.7999999999999998e-6 < phi2 < 2.39999999999999987e-12Initial program 62.8%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
cos-negN/A
mul-1-negN/A
lower-+.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-cos.f64N/A
cos-negN/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6491.8
Applied rewrites91.8%
Taylor expanded in phi2 around 0
sin-+PI/2-revN/A
cos-diff-revN/A
+-commutativeN/A
cos-diff-revN/A
*-commutativeN/A
lower-fma.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-sin.f6462.6
Applied rewrites62.6%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
lower-fma.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f6491.6
Applied rewrites91.6%
if 2.39999999999999987e-12 < phi2 Initial program 85.3%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
cos-negN/A
mul-1-negN/A
lower-+.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-cos.f64N/A
cos-negN/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6499.4
Applied rewrites99.4%
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
distribute-lft-inN/A
lower-fma.f64N/A
Applied rewrites99.3%
Applied rewrites99.3%
Taylor expanded in lambda1 around 0
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f6485.5
Applied rewrites85.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
(if (<= phi2 -2.5e-15)
(*
(-
(/ PI 2.0)
(asin
(fma
(* (cos (- lambda1 lambda2)) (cos phi2))
(cos phi1)
(* (sin phi2) (sin phi1)))))
R)
(if (<= phi2 2.4e-12)
(*
(acos
(fma
(* (cos lambda2) (cos lambda1))
(cos phi1)
(* (* (sin lambda2) (sin lambda1)) (cos phi1))))
R)
(*
(acos
(fma
(* (cos phi2) (cos phi1))
(* (cos lambda1) (cos lambda2))
(* (sin phi1) (sin phi2))))
R))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= -2.5e-15) {
tmp = ((((double) M_PI) / 2.0) - asin(fma((cos((lambda1 - lambda2)) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1))))) * R;
} else if (phi2 <= 2.4e-12) {
tmp = acos(fma((cos(lambda2) * cos(lambda1)), cos(phi1), ((sin(lambda2) * sin(lambda1)) * cos(phi1)))) * R;
} else {
tmp = acos(fma((cos(phi2) * cos(phi1)), (cos(lambda1) * cos(lambda2)), (sin(phi1) * sin(phi2)))) * R;
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= -2.5e-15) tmp = Float64(Float64(Float64(pi / 2.0) - asin(fma(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1))))) * R); elseif (phi2 <= 2.4e-12) tmp = Float64(acos(fma(Float64(cos(lambda2) * cos(lambda1)), cos(phi1), Float64(Float64(sin(lambda2) * sin(lambda1)) * cos(phi1)))) * R); else tmp = Float64(acos(fma(Float64(cos(phi2) * cos(phi1)), Float64(cos(lambda1) * cos(lambda2)), Float64(sin(phi1) * sin(phi2)))) * R); 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_] := If[LessEqual[phi2, -2.5e-15], N[(N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi2, 2.4e-12], N[(N[ArcCos[N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq -2.5 \cdot 10^{-15}:\\
\;\;\;\;\left(\frac{\pi}{2} - \sin^{-1} \left(\mathsf{fma}\left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right) \cdot R\\
\mathbf{elif}\;\phi_2 \leq 2.4 \cdot 10^{-12}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2 \cdot \cos \lambda_1, \cos \phi_1, \left(\sin \lambda_2 \cdot \sin \lambda_1\right) \cdot \cos \phi_1\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, \cos \lambda_1 \cdot \cos \lambda_2, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R\\
\end{array}
\end{array}
if phi2 < -2.5e-15Initial program 74.6%
lift-acos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f64N/A
acos-asinN/A
lower--.f64N/A
Applied rewrites74.7%
if -2.5e-15 < phi2 < 2.39999999999999987e-12Initial program 62.9%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6462.8
Applied rewrites62.8%
lift-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
cos-diff-revN/A
distribute-rgt-inN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-cos.f6492.3
Applied rewrites92.3%
if 2.39999999999999987e-12 < phi2 Initial program 85.3%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
cos-negN/A
mul-1-negN/A
lower-+.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-cos.f64N/A
cos-negN/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6499.4
Applied rewrites99.4%
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
distribute-lft-inN/A
lower-fma.f64N/A
Applied rewrites99.3%
Applied rewrites99.3%
Taylor expanded in lambda1 around 0
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f6485.5
Applied rewrites85.5%
Final simplification86.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 (* (cos (- lambda1 lambda2)) (cos phi2))))
(if (<= phi2 -2.5e-15)
(* (- (/ PI 2.0) (asin (fma t_0 (cos phi1) (* (sin phi2) (sin phi1))))) R)
(if (<= phi2 2.4e-12)
(*
(acos
(fma
(* (cos lambda2) (cos lambda1))
(cos phi1)
(* (* (sin lambda2) (sin lambda1)) (cos phi1))))
R)
(* (acos (fma (sin phi2) (sin phi1) (* t_0 (cos phi1)))) R)))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2)) * cos(phi2);
double tmp;
if (phi2 <= -2.5e-15) {
tmp = ((((double) M_PI) / 2.0) - asin(fma(t_0, cos(phi1), (sin(phi2) * sin(phi1))))) * R;
} else if (phi2 <= 2.4e-12) {
tmp = acos(fma((cos(lambda2) * cos(lambda1)), cos(phi1), ((sin(lambda2) * sin(lambda1)) * cos(phi1)))) * R;
} else {
tmp = acos(fma(sin(phi2), sin(phi1), (t_0 * cos(phi1)))) * R;
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2)) tmp = 0.0 if (phi2 <= -2.5e-15) tmp = Float64(Float64(Float64(pi / 2.0) - asin(fma(t_0, cos(phi1), Float64(sin(phi2) * sin(phi1))))) * R); elseif (phi2 <= 2.4e-12) tmp = Float64(acos(fma(Float64(cos(lambda2) * cos(lambda1)), cos(phi1), Float64(Float64(sin(lambda2) * sin(lambda1)) * cos(phi1)))) * R); else tmp = Float64(acos(fma(sin(phi2), sin(phi1), Float64(t_0 * cos(phi1)))) * R); 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[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -2.5e-15], N[(N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(t$95$0 * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi2, 2.4e-12], N[(N[ArcCos[N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\\
\mathbf{if}\;\phi_2 \leq -2.5 \cdot 10^{-15}:\\
\;\;\;\;\left(\frac{\pi}{2} - \sin^{-1} \left(\mathsf{fma}\left(t\_0, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right)\right) \cdot R\\
\mathbf{elif}\;\phi_2 \leq 2.4 \cdot 10^{-12}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2 \cdot \cos \lambda_1, \cos \phi_1, \left(\sin \lambda_2 \cdot \sin \lambda_1\right) \cdot \cos \phi_1\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, t\_0 \cdot \cos \phi_1\right)\right) \cdot R\\
\end{array}
\end{array}
if phi2 < -2.5e-15Initial program 74.6%
lift-acos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f64N/A
acos-asinN/A
lower--.f64N/A
Applied rewrites74.7%
if -2.5e-15 < phi2 < 2.39999999999999987e-12Initial program 62.9%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6462.8
Applied rewrites62.8%
lift-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
cos-diff-revN/A
distribute-rgt-inN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-cos.f6492.3
Applied rewrites92.3%
if 2.39999999999999987e-12 < phi2 Initial program 85.3%
lift-+.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-fma.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.3%
Final simplification86.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 (* (sin phi2) (sin phi1))))
(if (or (<= lambda2 -470.0) (not (<= lambda2 0.00092)))
(* (acos (fma (* (cos lambda2) (cos phi2)) (cos phi1) t_0)) R)
(* (acos (fma (* (cos lambda1) (cos phi1)) (cos phi2) t_0)) R))))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(phi2) * sin(phi1);
double tmp;
if ((lambda2 <= -470.0) || !(lambda2 <= 0.00092)) {
tmp = acos(fma((cos(lambda2) * cos(phi2)), cos(phi1), t_0)) * R;
} else {
tmp = acos(fma((cos(lambda1) * cos(phi1)), cos(phi2), t_0)) * R;
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(sin(phi2) * sin(phi1)) tmp = 0.0 if ((lambda2 <= -470.0) || !(lambda2 <= 0.00092)) tmp = Float64(acos(fma(Float64(cos(lambda2) * cos(phi2)), cos(phi1), t_0)) * R); else tmp = Float64(acos(fma(Float64(cos(lambda1) * cos(phi1)), cos(phi2), t_0)) * R); 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[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[lambda2, -470.0], N[Not[LessEqual[lambda2, 0.00092]], $MachinePrecision]], N[(N[ArcCos[N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \phi_2 \cdot \sin \phi_1\\
\mathbf{if}\;\lambda_2 \leq -470 \lor \neg \left(\lambda_2 \leq 0.00092\right):\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2 \cdot \cos \phi_2, \cos \phi_1, t\_0\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1 \cdot \cos \phi_1, \cos \phi_2, t\_0\right)\right) \cdot R\\
\end{array}
\end{array}
if lambda2 < -470 or 9.2000000000000003e-4 < lambda2 Initial program 56.4%
Taylor expanded in lambda1 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
cos-negN/A
lower-cos.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f6456.6
Applied rewrites56.6%
if -470 < lambda2 < 9.2000000000000003e-4Initial program 89.4%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
cos-negN/A
mul-1-negN/A
lower-+.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-cos.f64N/A
cos-negN/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6490.9
Applied rewrites90.9%
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
distribute-lft-inN/A
lower-fma.f64N/A
Applied rewrites90.9%
Taylor expanded in lambda2 around 0
distribute-lft-outN/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
cos-diffN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites89.4%
Final simplification71.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
(if (<= lambda2 -470.0)
(*
(acos
(fma (* (cos lambda2) (cos phi2)) (cos phi1) (* (sin phi2) (sin phi1))))
R)
(if (<= lambda2 0.00092)
(*
(acos
(fma (sin phi2) (sin phi1) (* (cos lambda1) (* (cos phi2) (cos phi1)))))
R)
(*
(acos
(fma (* (cos phi1) (cos phi2)) (cos lambda2) (* (sin phi1) (sin phi2))))
R))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda2 <= -470.0) {
tmp = acos(fma((cos(lambda2) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1)))) * R;
} else if (lambda2 <= 0.00092) {
tmp = acos(fma(sin(phi2), sin(phi1), (cos(lambda1) * (cos(phi2) * cos(phi1))))) * R;
} else {
tmp = acos(fma((cos(phi1) * cos(phi2)), cos(lambda2), (sin(phi1) * sin(phi2)))) * R;
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (lambda2 <= -470.0) tmp = Float64(acos(fma(Float64(cos(lambda2) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1)))) * R); elseif (lambda2 <= 0.00092) tmp = Float64(acos(fma(sin(phi2), sin(phi1), Float64(cos(lambda1) * Float64(cos(phi2) * cos(phi1))))) * R); else tmp = Float64(acos(fma(Float64(cos(phi1) * cos(phi2)), cos(lambda2), Float64(sin(phi1) * sin(phi2)))) * R); 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_] := If[LessEqual[lambda2, -470.0], N[(N[ArcCos[N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[lambda2, 0.00092], N[(N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -470:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2 \cdot \cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R\\
\mathbf{elif}\;\lambda_2 \leq 0.00092:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \lambda_1 \cdot \left(\cos \phi_2 \cdot \cos \phi_1\right)\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1 \cdot \cos \phi_2, \cos \lambda_2, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R\\
\end{array}
\end{array}
if lambda2 < -470Initial program 55.4%
Taylor expanded in lambda1 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
cos-negN/A
lower-cos.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f6455.6
Applied rewrites55.6%
if -470 < lambda2 < 9.2000000000000003e-4Initial program 89.4%
Taylor expanded in lambda1 around inf
Applied rewrites89.4%
lift-+.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-sin.f64N/A
lift-sin.f6489.5
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f6489.5
Applied rewrites89.5%
if 9.2000000000000003e-4 < lambda2 Initial program 57.3%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6426.0
Applied rewrites26.0%
Applied rewrites26.0%
Taylor expanded in lambda1 around 0
cos-neg-revN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f6457.7
Applied rewrites57.7%
Final simplification71.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 (* (sin phi2) (sin phi1))))
(if (<= lambda2 -470.0)
(* (acos (fma (* (cos lambda2) (cos phi2)) (cos phi1) t_0)) R)
(if (<= lambda2 0.00092)
(* (acos (fma (* (cos lambda1) (cos phi1)) (cos phi2) t_0)) R)
(*
(acos
(fma
(* (cos phi1) (cos phi2))
(cos lambda2)
(* (sin phi1) (sin phi2))))
R)))))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(phi2) * sin(phi1);
double tmp;
if (lambda2 <= -470.0) {
tmp = acos(fma((cos(lambda2) * cos(phi2)), cos(phi1), t_0)) * R;
} else if (lambda2 <= 0.00092) {
tmp = acos(fma((cos(lambda1) * cos(phi1)), cos(phi2), t_0)) * R;
} else {
tmp = acos(fma((cos(phi1) * cos(phi2)), cos(lambda2), (sin(phi1) * sin(phi2)))) * R;
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(sin(phi2) * sin(phi1)) tmp = 0.0 if (lambda2 <= -470.0) tmp = Float64(acos(fma(Float64(cos(lambda2) * cos(phi2)), cos(phi1), t_0)) * R); elseif (lambda2 <= 0.00092) tmp = Float64(acos(fma(Float64(cos(lambda1) * cos(phi1)), cos(phi2), t_0)) * R); else tmp = Float64(acos(fma(Float64(cos(phi1) * cos(phi2)), cos(lambda2), Float64(sin(phi1) * sin(phi2)))) * R); 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[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda2, -470.0], N[(N[ArcCos[N[(N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[lambda2, 0.00092], N[(N[ArcCos[N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \phi_2 \cdot \sin \phi_1\\
\mathbf{if}\;\lambda_2 \leq -470:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2 \cdot \cos \phi_2, \cos \phi_1, t\_0\right)\right) \cdot R\\
\mathbf{elif}\;\lambda_2 \leq 0.00092:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1 \cdot \cos \phi_1, \cos \phi_2, t\_0\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1 \cdot \cos \phi_2, \cos \lambda_2, \sin \phi_1 \cdot \sin \phi_2\right)\right) \cdot R\\
\end{array}
\end{array}
if lambda2 < -470Initial program 55.4%
Taylor expanded in lambda1 around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
cos-negN/A
lower-cos.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f6455.6
Applied rewrites55.6%
if -470 < lambda2 < 9.2000000000000003e-4Initial program 89.4%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
cos-negN/A
mul-1-negN/A
lower-+.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-cos.f64N/A
cos-negN/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6490.9
Applied rewrites90.9%
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
distribute-lft-inN/A
lower-fma.f64N/A
Applied rewrites90.9%
Taylor expanded in lambda2 around 0
distribute-lft-outN/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
cos-diffN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites89.4%
if 9.2000000000000003e-4 < lambda2 Initial program 57.3%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6426.0
Applied rewrites26.0%
Applied rewrites26.0%
Taylor expanded in lambda1 around 0
cos-neg-revN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f6457.7
Applied rewrites57.7%
Final simplification71.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
(if (<= lambda2 -4.3e+30)
(* (acos (* (cos (- lambda1 lambda2)) (cos phi2))) R)
(if (<= lambda2 5.3e+18)
(*
(acos
(fma (* (cos lambda1) (cos phi1)) (cos phi2) (* (sin phi2) (sin phi1))))
R)
(*
(acos
(+ (* (cos lambda1) (cos lambda2)) (* (sin lambda1) (sin lambda2))))
R))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda2 <= -4.3e+30) {
tmp = acos((cos((lambda1 - lambda2)) * cos(phi2))) * R;
} else if (lambda2 <= 5.3e+18) {
tmp = acos(fma((cos(lambda1) * cos(phi1)), cos(phi2), (sin(phi2) * sin(phi1)))) * R;
} else {
tmp = acos(((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2)))) * R;
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (lambda2 <= -4.3e+30) tmp = Float64(acos(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2))) * R); elseif (lambda2 <= 5.3e+18) tmp = Float64(acos(fma(Float64(cos(lambda1) * cos(phi1)), cos(phi2), Float64(sin(phi2) * sin(phi1)))) * R); else tmp = Float64(acos(Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2)))) * R); 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_] := If[LessEqual[lambda2, -4.3e+30], N[(N[ArcCos[N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[lambda2, 5.3e+18], N[(N[ArcCos[N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -4.3 \cdot 10^{+30}:\\
\;\;\;\;\cos^{-1} \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot R\\
\mathbf{elif}\;\lambda_2 \leq 5.3 \cdot 10^{+18}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1 \cdot \cos \phi_1, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot R\\
\end{array}
\end{array}
if lambda2 < -4.3e30Initial program 57.0%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6440.3
Applied rewrites40.3%
if -4.3e30 < lambda2 < 5.3e18Initial program 85.2%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
cos-negN/A
mul-1-negN/A
lower-+.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-cos.f64N/A
cos-negN/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6491.5
Applied rewrites91.5%
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
distribute-lft-inN/A
lower-fma.f64N/A
Applied rewrites91.5%
Taylor expanded in lambda2 around 0
distribute-lft-outN/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
cos-diffN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites84.3%
if 5.3e18 < lambda2 Initial program 58.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6440.4
Applied rewrites40.4%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6428.6
Applied rewrites28.6%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
*-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f6442.1
Applied rewrites42.1%
Final simplification62.4%
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
(if (<= lambda2 -4.3e+30)
(* (acos (* (cos (- lambda1 lambda2)) (cos phi2))) R)
(if (<= lambda2 5.3e+18)
(*
(acos
(fma (cos lambda1) (* (cos phi2) (cos phi1)) (* (sin phi2) (sin phi1))))
R)
(*
(acos
(+ (* (cos lambda1) (cos lambda2)) (* (sin lambda1) (sin lambda2))))
R))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda2 <= -4.3e+30) {
tmp = acos((cos((lambda1 - lambda2)) * cos(phi2))) * R;
} else if (lambda2 <= 5.3e+18) {
tmp = acos(fma(cos(lambda1), (cos(phi2) * cos(phi1)), (sin(phi2) * sin(phi1)))) * R;
} else {
tmp = acos(((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2)))) * R;
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (lambda2 <= -4.3e+30) tmp = Float64(acos(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2))) * R); elseif (lambda2 <= 5.3e+18) tmp = Float64(acos(fma(cos(lambda1), Float64(cos(phi2) * cos(phi1)), Float64(sin(phi2) * sin(phi1)))) * R); else tmp = Float64(acos(Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2)))) * R); 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_] := If[LessEqual[lambda2, -4.3e+30], N[(N[ArcCos[N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[lambda2, 5.3e+18], N[(N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -4.3 \cdot 10^{+30}:\\
\;\;\;\;\cos^{-1} \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot R\\
\mathbf{elif}\;\lambda_2 \leq 5.3 \cdot 10^{+18}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1, \cos \phi_2 \cdot \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right) \cdot R\\
\end{array}
\end{array}
if lambda2 < -4.3e30Initial program 57.0%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6440.3
Applied rewrites40.3%
if -4.3e30 < lambda2 < 5.3e18Initial program 85.2%
Taylor expanded in lambda2 around 0
lower-fma.f64N/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f6484.2
Applied rewrites84.2%
if 5.3e18 < lambda2 Initial program 58.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6440.4
Applied rewrites40.4%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6428.6
Applied rewrites28.6%
lift--.f64N/A
lift-cos.f64N/A
cos-diffN/A
*-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f6442.1
Applied rewrites42.1%
Final simplification62.4%
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
(*
(acos
(fma
(sin phi2)
(sin phi1)
(* (* (cos (- lambda1 lambda2)) (cos phi2)) (cos phi1))))
R))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(fma(sin(phi2), sin(phi1), ((cos((lambda1 - lambda2)) * cos(phi2)) * cos(phi1)))) * R;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(fma(sin(phi2), sin(phi1), Float64(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2)) * cos(phi1)))) * R) end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1\right)\right) \cdot R
\end{array}
Initial program 71.3%
lift-+.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-fma.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites71.4%
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 (cos (- lambda1 lambda2))))
(if (<= phi1 -8.1e-7)
(* (- (/ PI 2.0) (asin (* t_0 (cos phi1)))) R)
(* (acos (+ (* (sin phi1) (sin phi2)) (* (cos phi2) t_0))) R))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double tmp;
if (phi1 <= -8.1e-7) {
tmp = ((((double) M_PI) / 2.0) - asin((t_0 * cos(phi1)))) * R;
} else {
tmp = acos(((sin(phi1) * sin(phi2)) + (cos(phi2) * t_0))) * R;
}
return tmp;
}
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.cos((lambda1 - lambda2));
double tmp;
if (phi1 <= -8.1e-7) {
tmp = ((Math.PI / 2.0) - Math.asin((t_0 * Math.cos(phi1)))) * R;
} else {
tmp = Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + (Math.cos(phi2) * t_0))) * R;
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((lambda1 - lambda2)) tmp = 0 if phi1 <= -8.1e-7: tmp = ((math.pi / 2.0) - math.asin((t_0 * math.cos(phi1)))) * R else: tmp = math.acos(((math.sin(phi1) * math.sin(phi2)) + (math.cos(phi2) * t_0))) * R return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi1 <= -8.1e-7) tmp = Float64(Float64(Float64(pi / 2.0) - asin(Float64(t_0 * cos(phi1)))) * R); else tmp = Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(cos(phi2) * t_0))) * R); 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 = cos((lambda1 - lambda2));
tmp = 0.0;
if (phi1 <= -8.1e-7)
tmp = ((pi / 2.0) - asin((t_0 * cos(phi1)))) * R;
else
tmp = acos(((sin(phi1) * sin(phi2)) + (cos(phi2) * t_0))) * R;
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[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -8.1e-7], N[(N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_1 \leq -8.1 \cdot 10^{-7}:\\
\;\;\;\;\left(\frac{\pi}{2} - \sin^{-1} \left(t\_0 \cdot \cos \phi_1\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot t\_0\right) \cdot R\\
\end{array}
\end{array}
if phi1 < -8.09999999999999974e-7Initial program 73.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6444.4
Applied rewrites44.4%
lift-acos.f64N/A
acos-asinN/A
lift-/.f64N/A
lift-PI.f64N/A
lower--.f64N/A
lower-asin.f6444.4
Applied rewrites44.4%
if -8.09999999999999974e-7 < phi1 Initial program 70.3%
Taylor expanded in phi1 around 0
lift-cos.f6451.5
Applied rewrites51.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 (cos (- lambda1 lambda2))))
(if (<= phi2 5.8e-19)
(* (acos (+ (* (sin phi1) (sin phi2)) (* (cos phi1) t_0))) R)
(* (acos (* t_0 (cos phi2))) R))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double tmp;
if (phi2 <= 5.8e-19) {
tmp = acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * t_0))) * R;
} else {
tmp = acos((t_0 * cos(phi2))) * R;
}
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) :: tmp
t_0 = cos((lambda1 - lambda2))
if (phi2 <= 5.8d-19) then
tmp = acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * t_0))) * r
else
tmp = acos((t_0 * cos(phi2))) * r
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.cos((lambda1 - lambda2));
double tmp;
if (phi2 <= 5.8e-19) {
tmp = Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + (Math.cos(phi1) * t_0))) * R;
} else {
tmp = Math.acos((t_0 * Math.cos(phi2))) * R;
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((lambda1 - lambda2)) tmp = 0 if phi2 <= 5.8e-19: tmp = math.acos(((math.sin(phi1) * math.sin(phi2)) + (math.cos(phi1) * t_0))) * R else: tmp = math.acos((t_0 * math.cos(phi2))) * R return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi2 <= 5.8e-19) tmp = Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(cos(phi1) * t_0))) * R); else tmp = Float64(acos(Float64(t_0 * cos(phi2))) * R); 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 = cos((lambda1 - lambda2));
tmp = 0.0;
if (phi2 <= 5.8e-19)
tmp = acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * t_0))) * R;
else
tmp = acos((t_0 * cos(phi2))) * R;
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[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 5.8e-19], N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq 5.8 \cdot 10^{-19}:\\
\;\;\;\;\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot t\_0\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \phi_2\right) \cdot R\\
\end{array}
\end{array}
if phi2 < 5.8e-19Initial program 66.6%
Taylor expanded in phi2 around 0
lift-cos.f6449.4
Applied rewrites49.4%
if 5.8e-19 < phi2 Initial program 84.5%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6452.5
Applied rewrites52.5%
Final simplification50.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 (if (or (<= lambda2 -470.0) (not (<= lambda2 0.00092))) (* (acos (* (cos lambda2) (cos phi1))) R) (* (acos (* (cos lambda1) (cos phi1))) R)))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if ((lambda2 <= -470.0) || !(lambda2 <= 0.00092)) {
tmp = acos((cos(lambda2) * cos(phi1))) * R;
} else {
tmp = acos((cos(lambda1) * cos(phi1))) * R;
}
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) :: tmp
if ((lambda2 <= (-470.0d0)) .or. (.not. (lambda2 <= 0.00092d0))) then
tmp = acos((cos(lambda2) * cos(phi1))) * r
else
tmp = acos((cos(lambda1) * cos(phi1))) * r
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 tmp;
if ((lambda2 <= -470.0) || !(lambda2 <= 0.00092)) {
tmp = Math.acos((Math.cos(lambda2) * Math.cos(phi1))) * R;
} else {
tmp = Math.acos((Math.cos(lambda1) * Math.cos(phi1))) * R;
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if (lambda2 <= -470.0) or not (lambda2 <= 0.00092): tmp = math.acos((math.cos(lambda2) * math.cos(phi1))) * R else: tmp = math.acos((math.cos(lambda1) * math.cos(phi1))) * R return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if ((lambda2 <= -470.0) || !(lambda2 <= 0.00092)) tmp = Float64(acos(Float64(cos(lambda2) * cos(phi1))) * R); else tmp = Float64(acos(Float64(cos(lambda1) * cos(phi1))) * R); 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)
tmp = 0.0;
if ((lambda2 <= -470.0) || ~((lambda2 <= 0.00092)))
tmp = acos((cos(lambda2) * cos(phi1))) * R;
else
tmp = acos((cos(lambda1) * cos(phi1))) * R;
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_] := If[Or[LessEqual[lambda2, -470.0], N[Not[LessEqual[lambda2, 0.00092]], $MachinePrecision]], N[(N[ArcCos[N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -470 \lor \neg \left(\lambda_2 \leq 0.00092\right):\\
\;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_1\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_1\right) \cdot R\\
\end{array}
\end{array}
if lambda2 < -470 or 9.2000000000000003e-4 < lambda2 Initial program 56.4%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6435.8
Applied rewrites35.8%
Taylor expanded in lambda1 around 0
cos-neg-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f6436.0
Applied rewrites36.0%
if -470 < lambda2 < 9.2000000000000003e-4Initial program 89.4%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6448.2
Applied rewrites48.2%
Taylor expanded in lambda1 around inf
Applied rewrites48.2%
Final simplification41.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 (cos (- lambda1 lambda2))))
(if (<= phi2 5.8e-19)
(* (acos (* t_0 (cos phi1))) R)
(* (acos (* t_0 (cos phi2))) R))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double tmp;
if (phi2 <= 5.8e-19) {
tmp = acos((t_0 * cos(phi1))) * R;
} else {
tmp = acos((t_0 * cos(phi2))) * R;
}
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) :: tmp
t_0 = cos((lambda1 - lambda2))
if (phi2 <= 5.8d-19) then
tmp = acos((t_0 * cos(phi1))) * r
else
tmp = acos((t_0 * cos(phi2))) * r
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.cos((lambda1 - lambda2));
double tmp;
if (phi2 <= 5.8e-19) {
tmp = Math.acos((t_0 * Math.cos(phi1))) * R;
} else {
tmp = Math.acos((t_0 * Math.cos(phi2))) * R;
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((lambda1 - lambda2)) tmp = 0 if phi2 <= 5.8e-19: tmp = math.acos((t_0 * math.cos(phi1))) * R else: tmp = math.acos((t_0 * math.cos(phi2))) * R return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi2 <= 5.8e-19) tmp = Float64(acos(Float64(t_0 * cos(phi1))) * R); else tmp = Float64(acos(Float64(t_0 * cos(phi2))) * R); 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 = cos((lambda1 - lambda2));
tmp = 0.0;
if (phi2 <= 5.8e-19)
tmp = acos((t_0 * cos(phi1))) * R;
else
tmp = acos((t_0 * cos(phi2))) * R;
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[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 5.8e-19], N[(N[ArcCos[N[(t$95$0 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq 5.8 \cdot 10^{-19}:\\
\;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \phi_1\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \phi_2\right) \cdot R\\
\end{array}
\end{array}
if phi2 < 5.8e-19Initial program 66.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6449.3
Applied rewrites49.3%
if 5.8e-19 < phi2 Initial program 84.5%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6452.5
Applied rewrites52.5%
Final simplification50.1%
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 (cos (- lambda1 lambda2)))) (if (<= t_0 0.99995) (* (acos t_0) R) (* (acos (cos phi1)) R))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double tmp;
if (t_0 <= 0.99995) {
tmp = acos(t_0) * R;
} else {
tmp = acos(cos(phi1)) * R;
}
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) :: tmp
t_0 = cos((lambda1 - lambda2))
if (t_0 <= 0.99995d0) then
tmp = acos(t_0) * r
else
tmp = acos(cos(phi1)) * r
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.cos((lambda1 - lambda2));
double tmp;
if (t_0 <= 0.99995) {
tmp = Math.acos(t_0) * R;
} else {
tmp = Math.acos(Math.cos(phi1)) * R;
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((lambda1 - lambda2)) tmp = 0 if t_0 <= 0.99995: tmp = math.acos(t_0) * R else: tmp = math.acos(math.cos(phi1)) * R return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (t_0 <= 0.99995) tmp = Float64(acos(t_0) * R); else tmp = Float64(acos(cos(phi1)) * R); 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 = cos((lambda1 - lambda2));
tmp = 0.0;
if (t_0 <= 0.99995)
tmp = acos(t_0) * R;
else
tmp = acos(cos(phi1)) * R;
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[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.99995], N[(N[ArcCos[t$95$0], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;t\_0 \leq 0.99995:\\
\;\;\;\;\cos^{-1} t\_0 \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
\end{array}
\end{array}
if (cos.f64 (-.f64 lambda1 lambda2)) < 0.999950000000000006Initial program 67.4%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6440.8
Applied rewrites40.8%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6431.3
Applied rewrites31.3%
if 0.999950000000000006 < (cos.f64 (-.f64 lambda1 lambda2)) Initial program 83.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6443.4
Applied rewrites43.4%
Taylor expanded in lambda2 around 0
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f6443.4
Applied rewrites43.4%
Taylor expanded in lambda1 around 0
lift-cos.f6443.4
Applied rewrites43.4%
Final simplification34.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 (if (<= phi1 -0.0048) (* (acos (* (cos lambda2) (cos phi1))) R) (* (acos (cos (- lambda1 lambda2))) R)))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -0.0048) {
tmp = acos((cos(lambda2) * cos(phi1))) * R;
} else {
tmp = acos(cos((lambda1 - lambda2))) * R;
}
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) :: tmp
if (phi1 <= (-0.0048d0)) then
tmp = acos((cos(lambda2) * cos(phi1))) * r
else
tmp = acos(cos((lambda1 - lambda2))) * r
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 tmp;
if (phi1 <= -0.0048) {
tmp = Math.acos((Math.cos(lambda2) * Math.cos(phi1))) * R;
} else {
tmp = Math.acos(Math.cos((lambda1 - lambda2))) * R;
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi1 <= -0.0048: tmp = math.acos((math.cos(lambda2) * math.cos(phi1))) * R else: tmp = math.acos(math.cos((lambda1 - lambda2))) * R return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -0.0048) tmp = Float64(acos(Float64(cos(lambda2) * cos(phi1))) * R); else tmp = Float64(acos(cos(Float64(lambda1 - lambda2))) * R); 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)
tmp = 0.0;
if (phi1 <= -0.0048)
tmp = acos((cos(lambda2) * cos(phi1))) * R;
else
tmp = acos(cos((lambda1 - lambda2))) * R;
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_] := If[LessEqual[phi1, -0.0048], N[(N[ArcCos[N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -0.0048:\\
\;\;\;\;\cos^{-1} \left(\cos \lambda_2 \cdot \cos \phi_1\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R\\
\end{array}
\end{array}
if phi1 < -0.00479999999999999958Initial program 73.2%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6444.0
Applied rewrites44.0%
Taylor expanded in lambda1 around 0
cos-neg-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f6440.9
Applied rewrites40.9%
if -0.00479999999999999958 < phi1 Initial program 70.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6440.3
Applied rewrites40.3%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6429.9
Applied rewrites29.9%
Final simplification33.1%
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 (* (acos (* (cos (- lambda1 lambda2)) (cos phi1))) R))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos((cos((lambda1 - lambda2)) * cos(phi1))) * R;
}
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
code = acos((cos((lambda1 - lambda2)) * cos(phi1))) * r
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) {
return Math.acos((Math.cos((lambda1 - lambda2)) * Math.cos(phi1))) * R;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): return math.acos((math.cos((lambda1 - lambda2)) * math.cos(phi1))) * R
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi1))) * R) end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
tmp = acos((cos((lambda1 - lambda2)) * cos(phi1))) * R;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\cos^{-1} \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right) \cdot R
\end{array}
Initial program 71.3%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6441.4
Applied rewrites41.4%
Final simplification41.4%
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 (if (or (<= lambda2 -105000000.0) (not (<= lambda2 0.00092))) (* (acos (cos lambda2)) R) (* (acos (cos lambda1)) R)))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if ((lambda2 <= -105000000.0) || !(lambda2 <= 0.00092)) {
tmp = acos(cos(lambda2)) * R;
} else {
tmp = acos(cos(lambda1)) * R;
}
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) :: tmp
if ((lambda2 <= (-105000000.0d0)) .or. (.not. (lambda2 <= 0.00092d0))) then
tmp = acos(cos(lambda2)) * r
else
tmp = acos(cos(lambda1)) * r
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 tmp;
if ((lambda2 <= -105000000.0) || !(lambda2 <= 0.00092)) {
tmp = Math.acos(Math.cos(lambda2)) * R;
} else {
tmp = Math.acos(Math.cos(lambda1)) * R;
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if (lambda2 <= -105000000.0) or not (lambda2 <= 0.00092): tmp = math.acos(math.cos(lambda2)) * R else: tmp = math.acos(math.cos(lambda1)) * R return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if ((lambda2 <= -105000000.0) || !(lambda2 <= 0.00092)) tmp = Float64(acos(cos(lambda2)) * R); else tmp = Float64(acos(cos(lambda1)) * R); 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)
tmp = 0.0;
if ((lambda2 <= -105000000.0) || ~((lambda2 <= 0.00092)))
tmp = acos(cos(lambda2)) * R;
else
tmp = acos(cos(lambda1)) * R;
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_] := If[Or[LessEqual[lambda2, -105000000.0], N[Not[LessEqual[lambda2, 0.00092]], $MachinePrecision]], N[(N[ArcCos[N[Cos[lambda2], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[lambda1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq -105000000 \lor \neg \left(\lambda_2 \leq 0.00092\right):\\
\;\;\;\;\cos^{-1} \cos \lambda_2 \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \cos \lambda_1 \cdot R\\
\end{array}
\end{array}
if lambda2 < -1.05e8 or 9.2000000000000003e-4 < lambda2 Initial program 56.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6435.9
Applied rewrites35.9%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6426.5
Applied rewrites26.5%
Taylor expanded in lambda1 around 0
cos-neg-revN/A
lift-cos.f6426.6
Applied rewrites26.6%
if -1.05e8 < lambda2 < 9.2000000000000003e-4Initial program 88.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6447.9
Applied rewrites47.9%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6425.0
Applied rewrites25.0%
Taylor expanded in lambda2 around 0
lift-cos.f6425.0
Applied rewrites25.0%
Final simplification25.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 (if (<= phi1 -0.0048) (* (acos (cos phi1)) R) (* (acos (cos lambda1)) R)))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -0.0048) {
tmp = acos(cos(phi1)) * R;
} else {
tmp = acos(cos(lambda1)) * R;
}
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) :: tmp
if (phi1 <= (-0.0048d0)) then
tmp = acos(cos(phi1)) * r
else
tmp = acos(cos(lambda1)) * r
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 tmp;
if (phi1 <= -0.0048) {
tmp = Math.acos(Math.cos(phi1)) * R;
} else {
tmp = Math.acos(Math.cos(lambda1)) * R;
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi1 <= -0.0048: tmp = math.acos(math.cos(phi1)) * R else: tmp = math.acos(math.cos(lambda1)) * R return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -0.0048) tmp = Float64(acos(cos(phi1)) * R); else tmp = Float64(acos(cos(lambda1)) * R); 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)
tmp = 0.0;
if (phi1 <= -0.0048)
tmp = acos(cos(phi1)) * R;
else
tmp = acos(cos(lambda1)) * R;
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_] := If[LessEqual[phi1, -0.0048], N[(N[ArcCos[N[Cos[phi1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[lambda1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -0.0048:\\
\;\;\;\;\cos^{-1} \cos \phi_1 \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \cos \lambda_1 \cdot R\\
\end{array}
\end{array}
if phi1 < -0.00479999999999999958Initial program 73.2%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6444.0
Applied rewrites44.0%
Taylor expanded in lambda2 around 0
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f6424.4
Applied rewrites24.4%
Taylor expanded in lambda1 around 0
lift-cos.f6431.5
Applied rewrites31.5%
if -0.00479999999999999958 < phi1 Initial program 70.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6440.3
Applied rewrites40.3%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6429.9
Applied rewrites29.9%
Taylor expanded in lambda2 around 0
lift-cos.f6420.6
Applied rewrites20.6%
Final simplification23.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 (* (acos (cos lambda1)) R))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(cos(lambda1)) * R;
}
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
code = acos(cos(lambda1)) * r
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) {
return Math.acos(Math.cos(lambda1)) * R;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): return math.acos(math.cos(lambda1)) * R
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(cos(lambda1)) * R) end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
tmp = acos(cos(lambda1)) * R;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[Cos[lambda1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\cos^{-1} \cos \lambda_1 \cdot R
\end{array}
Initial program 71.3%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6441.4
Applied rewrites41.4%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6425.8
Applied rewrites25.8%
Taylor expanded in lambda2 around 0
lift-cos.f6418.0
Applied rewrites18.0%
Final simplification18.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 (* (acos 1.0) R))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(1.0) * R;
}
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
code = acos(1.0d0) * r
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) {
return Math.acos(1.0) * R;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): return math.acos(1.0) * R
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(1.0) * R) end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
tmp = acos(1.0) * R;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[1.0], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\cos^{-1} 1 \cdot R
\end{array}
Initial program 71.3%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6441.4
Applied rewrites41.4%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6425.8
Applied rewrites25.8%
Taylor expanded in lambda2 around 0
lift-cos.f6418.0
Applied rewrites18.0%
Taylor expanded in lambda1 around 0
Applied rewrites4.8%
Final simplification4.8%
herbie shell --seed 2025057
(FPCore (R lambda1 lambda2 phi1 phi2)
:name "Spherical law of cosines"
:precision binary64
(* (acos (+ (* (sin phi1) (sin phi2)) (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2))))) R))