
(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}
Herbie found 19 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}
(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))
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;
}
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
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}
\\
\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 73.5%
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.f6493.9
Applied rewrites93.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(*
(acos
(fma
(* (cos (- lambda1 lambda2)) (cos phi2))
(cos phi1)
(* (sin phi2) (sin phi1))))
R)))
(if (<= phi1 -1000.0)
t_0
(if (<= phi1 7.5e-17)
(*
(acos
(+
(*
(*
phi1
(fma
(* phi1 phi1)
(- (* 0.008333333333333333 (* phi1 phi1)) 0.16666666666666666)
1.0))
(sin phi2))
(*
(* (cos phi1) (cos phi2))
(fma (cos lambda1) (cos lambda2) (* (sin lambda1) (sin lambda2))))))
R)
t_0))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = acos(fma((cos((lambda1 - lambda2)) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1)))) * R;
double tmp;
if (phi1 <= -1000.0) {
tmp = t_0;
} else if (phi1 <= 7.5e-17) {
tmp = acos((((phi1 * fma((phi1 * phi1), ((0.008333333333333333 * (phi1 * phi1)) - 0.16666666666666666), 1.0)) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * fma(cos(lambda1), cos(lambda2), (sin(lambda1) * sin(lambda2)))))) * R;
} else {
tmp = t_0;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(acos(fma(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1)))) * R) tmp = 0.0 if (phi1 <= -1000.0) tmp = t_0; elseif (phi1 <= 7.5e-17) tmp = Float64(acos(Float64(Float64(Float64(phi1 * fma(Float64(phi1 * phi1), Float64(Float64(0.008333333333333333 * Float64(phi1 * phi1)) - 0.16666666666666666), 1.0)) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * fma(cos(lambda1), cos(lambda2), Float64(sin(lambda1) * sin(lambda2)))))) * R); else tmp = t_0; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[ArcCos[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] * R), $MachinePrecision]}, If[LessEqual[phi1, -1000.0], t$95$0, If[LessEqual[phi1, 7.5e-17], N[(N[ArcCos[N[(N[(N[(phi1 * N[(N[(phi1 * phi1), $MachinePrecision] * N[(N[(0.008333333333333333 * N[(phi1 * phi1), $MachinePrecision]), $MachinePrecision] - 0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $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], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-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) \cdot R\\
\mathbf{if}\;\phi_1 \leq -1000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\phi_1 \leq 7.5 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(\left(\phi_1 \cdot \mathsf{fma}\left(\phi_1 \cdot \phi_1, 0.008333333333333333 \cdot \left(\phi_1 \cdot \phi_1\right) - 0.16666666666666666, 1\right)\right) \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\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if phi1 < -1e3 or 7.49999999999999984e-17 < phi1 Initial program 79.7%
Applied rewrites79.7%
if -1e3 < phi1 < 7.49999999999999984e-17Initial program 67.2%
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.f6488.8
Applied rewrites88.8%
Taylor expanded in phi1 around 0
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6488.5
Applied rewrites88.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(*
(acos
(fma
(* (cos (- lambda1 lambda2)) (cos phi2))
(cos phi1)
(* (sin phi2) (sin phi1))))
R)))
(if (<= phi1 -1000.0)
t_0
(if (<= phi1 7.5e-17)
(*
(acos
(+
(* phi1 (sin phi2))
(*
(* (cos phi1) (cos phi2))
(fma (cos lambda1) (cos lambda2) (* (sin lambda1) (sin lambda2))))))
R)
t_0))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = acos(fma((cos((lambda1 - lambda2)) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1)))) * R;
double tmp;
if (phi1 <= -1000.0) {
tmp = t_0;
} else if (phi1 <= 7.5e-17) {
tmp = acos(((phi1 * sin(phi2)) + ((cos(phi1) * cos(phi2)) * fma(cos(lambda1), cos(lambda2), (sin(lambda1) * sin(lambda2)))))) * R;
} else {
tmp = t_0;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(acos(fma(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1)))) * R) tmp = 0.0 if (phi1 <= -1000.0) tmp = t_0; elseif (phi1 <= 7.5e-17) tmp = Float64(acos(Float64(Float64(phi1 * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * fma(cos(lambda1), cos(lambda2), Float64(sin(lambda1) * sin(lambda2)))))) * R); else tmp = t_0; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[ArcCos[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] * R), $MachinePrecision]}, If[LessEqual[phi1, -1000.0], t$95$0, If[LessEqual[phi1, 7.5e-17], N[(N[ArcCos[N[(N[(phi1 * 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], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-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) \cdot R\\
\mathbf{if}\;\phi_1 \leq -1000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\phi_1 \leq 7.5 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(\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\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if phi1 < -1e3 or 7.49999999999999984e-17 < phi1 Initial program 79.7%
Applied rewrites79.7%
if -1e3 < phi1 < 7.49999999999999984e-17Initial program 67.2%
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.f6488.8
Applied rewrites88.8%
Taylor expanded in phi1 around 0
Applied rewrites88.3%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(*
(acos
(fma
(* (cos (- lambda1 lambda2)) (cos phi2))
(cos phi1)
(* (sin phi2) (sin phi1))))
R)))
(if (<= phi1 -2.15e-6)
t_0
(if (<= phi1 7.5e-17)
(*
(acos
(fma
(sin phi2)
(sin phi1)
(*
(cos phi2)
(fma (cos lambda1) (cos lambda2) (* (sin lambda1) (sin lambda2))))))
R)
t_0))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = acos(fma((cos((lambda1 - lambda2)) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1)))) * R;
double tmp;
if (phi1 <= -2.15e-6) {
tmp = t_0;
} else if (phi1 <= 7.5e-17) {
tmp = acos(fma(sin(phi2), sin(phi1), (cos(phi2) * fma(cos(lambda1), cos(lambda2), (sin(lambda1) * sin(lambda2)))))) * R;
} else {
tmp = t_0;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(acos(fma(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1)))) * R) tmp = 0.0 if (phi1 <= -2.15e-6) tmp = t_0; elseif (phi1 <= 7.5e-17) tmp = Float64(acos(fma(sin(phi2), sin(phi1), Float64(cos(phi2) * fma(cos(lambda1), cos(lambda2), Float64(sin(lambda1) * sin(lambda2)))))) * R); else tmp = t_0; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[ArcCos[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] * R), $MachinePrecision]}, If[LessEqual[phi1, -2.15e-6], t$95$0, If[LessEqual[phi1, 7.5e-17], N[(N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[phi2], $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], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-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) \cdot R\\
\mathbf{if}\;\phi_1 \leq -2.15 \cdot 10^{-6}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\phi_1 \leq 7.5 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_2 \cdot \mathsf{fma}\left(\cos \lambda_1, \cos \lambda_2, \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if phi1 < -2.15000000000000017e-6 or 7.49999999999999984e-17 < phi1 Initial program 79.7%
Applied rewrites79.7%
if -2.15000000000000017e-6 < phi1 < 7.49999999999999984e-17Initial program 67.0%
Taylor expanded in phi1 around 0
lift-cos.f6467.0
Applied rewrites67.0%
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.f6467.0
Applied rewrites67.0%
lift--.f64N/A
lift-cos.f64N/A
cos-diff-revN/A
lower-fma.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f6488.6
Applied rewrites88.6%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(*
(acos
(fma
(* (cos lambda2) (cos phi2))
(cos phi1)
(* (sin phi2) (sin phi1))))
R)))
(if (<= lambda2 -6.0)
t_0
(if (<= lambda2 0.016)
(*
(acos
(fma
(sin phi2)
(sin phi1)
(* (cos lambda1) (* (cos phi1) (cos phi2)))))
R)
t_0))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = acos(fma((cos(lambda2) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1)))) * R;
double tmp;
if (lambda2 <= -6.0) {
tmp = t_0;
} else if (lambda2 <= 0.016) {
tmp = acos(fma(sin(phi2), sin(phi1), (cos(lambda1) * (cos(phi1) * cos(phi2))))) * R;
} else {
tmp = t_0;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(acos(fma(Float64(cos(lambda2) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1)))) * R) tmp = 0.0 if (lambda2 <= -6.0) tmp = t_0; elseif (lambda2 <= 0.016) tmp = Float64(acos(fma(sin(phi2), sin(phi1), Float64(cos(lambda1) * Float64(cos(phi1) * cos(phi2))))) * R); else tmp = t_0; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$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, -6.0], t$95$0, If[LessEqual[lambda2, 0.016], N[(N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \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{if}\;\lambda_2 \leq -6:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\lambda_2 \leq 0.016:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \lambda_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if lambda2 < -6 or 0.016 < lambda2 Initial program 59.9%
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.f6459.7
Applied rewrites59.7%
if -6 < lambda2 < 0.016Initial program 87.6%
Taylor expanded in phi1 around 0
lift-cos.f6445.6
Applied rewrites45.6%
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.f6445.6
Applied rewrites45.6%
Taylor expanded in lambda2 around 0
sin-+PI/2-revN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f6487.1
Applied rewrites87.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (sin phi2) (sin phi1)))
(t_1 (* (acos (fma (* (cos lambda2) (cos phi2)) (cos phi1) t_0)) R)))
(if (<= lambda2 -6.0)
t_1
(if (<= lambda2 0.016)
(* (acos (fma (cos lambda1) (* (cos phi2) (cos phi1)) t_0)) R)
t_1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(phi2) * sin(phi1);
double t_1 = acos(fma((cos(lambda2) * cos(phi2)), cos(phi1), t_0)) * R;
double tmp;
if (lambda2 <= -6.0) {
tmp = t_1;
} else if (lambda2 <= 0.016) {
tmp = acos(fma(cos(lambda1), (cos(phi2) * cos(phi1)), t_0)) * R;
} else {
tmp = t_1;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(sin(phi2) * sin(phi1)) t_1 = Float64(acos(fma(Float64(cos(lambda2) * cos(phi2)), cos(phi1), t_0)) * R) tmp = 0.0 if (lambda2 <= -6.0) tmp = t_1; elseif (lambda2 <= 0.016) tmp = Float64(acos(fma(cos(lambda1), Float64(cos(phi2) * cos(phi1)), t_0)) * R); else tmp = t_1; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = 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, -6.0], t$95$1, If[LessEqual[lambda2, 0.016], N[(N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \phi_2 \cdot \sin \phi_1\\
t_1 := \cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_2 \cdot \cos \phi_2, \cos \phi_1, t\_0\right)\right) \cdot R\\
\mathbf{if}\;\lambda_2 \leq -6:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;\lambda_2 \leq 0.016:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\cos \lambda_1, \cos \phi_2 \cdot \cos \phi_1, t\_0\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if lambda2 < -6 or 0.016 < lambda2 Initial program 59.9%
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.f6459.7
Applied rewrites59.7%
if -6 < lambda2 < 0.016Initial program 87.6%
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.f6487.1
Applied rewrites87.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(*
(acos
(fma
(cos lambda1)
(* (cos phi2) (cos phi1))
(* (sin phi2) (sin phi1))))
R)))
(if (<= phi1 -0.7)
t_0
(if (<= phi1 0.028)
(*
(acos
(+
(* phi1 (sin phi2))
(* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
R)
t_0))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = acos(fma(cos(lambda1), (cos(phi2) * cos(phi1)), (sin(phi2) * sin(phi1)))) * R;
double tmp;
if (phi1 <= -0.7) {
tmp = t_0;
} else if (phi1 <= 0.028) {
tmp = acos(((phi1 * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
} else {
tmp = t_0;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(acos(fma(cos(lambda1), Float64(cos(phi2) * cos(phi1)), Float64(sin(phi2) * sin(phi1)))) * R) tmp = 0.0 if (phi1 <= -0.7) tmp = t_0; elseif (phi1 <= 0.028) tmp = Float64(acos(Float64(Float64(phi1 * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))))) * R); else tmp = t_0; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = 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]}, If[LessEqual[phi1, -0.7], t$95$0, If[LessEqual[phi1, 0.028], N[(N[ArcCos[N[(N[(phi1 * 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], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \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{if}\;\phi_1 \leq -0.7:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\phi_1 \leq 0.028:\\
\;\;\;\;\cos^{-1} \left(\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\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if phi1 < -0.69999999999999996 or 0.0280000000000000006 < phi1 Initial program 79.9%
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.f6459.5
Applied rewrites59.5%
if -0.69999999999999996 < phi1 < 0.0280000000000000006Initial program 67.2%
Taylor expanded in phi1 around 0
Applied rewrites67.0%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(acos
(fma
(* (cos (- lambda1 lambda2)) (cos phi2))
(cos phi1)
(* (sin phi2) (sin phi1))))
R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(fma((cos((lambda1 - lambda2)) * cos(phi2)), cos(phi1), (sin(phi2) * sin(phi1)))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(fma(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2)), cos(phi1), Float64(sin(phi2) * sin(phi1)))) * R) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[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] * R), $MachinePrecision]
\begin{array}{l}
\\
\cos^{-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) \cdot R
\end{array}
Initial program 73.5%
Applied rewrites73.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(acos
(fma
(sin phi2)
(sin phi1)
(* (* (cos (- lambda1 lambda2)) (cos phi2)) (cos phi1))))
R))
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;
}
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
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}
\\
\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 73.5%
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 rewrites73.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- lambda1 lambda2))))
(if (<= phi2 1550.0)
(* (acos (fma (sin phi2) (sin phi1) (* (cos phi1) t_0))) R)
(* (acos (fma t_0 (cos phi2) (* (sin phi2) (sin phi1)))) R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double tmp;
if (phi2 <= 1550.0) {
tmp = acos(fma(sin(phi2), sin(phi1), (cos(phi1) * t_0))) * R;
} else {
tmp = acos(fma(t_0, cos(phi2), (sin(phi2) * sin(phi1)))) * R;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi2 <= 1550.0) tmp = Float64(acos(fma(sin(phi2), sin(phi1), Float64(cos(phi1) * t_0))) * R); else tmp = Float64(acos(fma(t_0, cos(phi2), Float64(sin(phi2) * sin(phi1)))) * R); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 1550.0], N[(N[ArcCos[N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $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] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq 1550:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_2, \sin \phi_1, \cos \phi_1 \cdot t\_0\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(t\_0, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R\\
\end{array}
\end{array}
if phi2 < 1550Initial program 72.0%
Taylor expanded in phi1 around 0
lift-cos.f6440.6
Applied rewrites40.6%
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.f6440.6
Applied rewrites40.6%
Taylor expanded in phi2 around 0
sin-+PI/2-revN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift--.f6450.9
Applied rewrites50.9%
if 1550 < phi2 Initial program 78.0%
Taylor expanded in phi1 around 0
lift-cos.f6447.4
Applied rewrites47.4%
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
*-commutativeN/A
lower-fma.f64N/A
lift-cos.f64N/A
lift--.f64N/A
*-commutativeN/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f6447.4
Applied rewrites47.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- lambda1 lambda2))))
(if (<= phi2 0.145)
(* (acos (* t_0 (cos phi1))) R)
(* (acos (fma t_0 (cos phi2) (* (sin phi2) (sin phi1)))) R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double tmp;
if (phi2 <= 0.145) {
tmp = acos((t_0 * cos(phi1))) * R;
} else {
tmp = acos(fma(t_0, cos(phi2), (sin(phi2) * sin(phi1)))) * R;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi2 <= 0.145) tmp = Float64(acos(Float64(t_0 * cos(phi1))) * R); else tmp = Float64(acos(fma(t_0, cos(phi2), Float64(sin(phi2) * sin(phi1)))) * R); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 0.145], 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] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq 0.145:\\
\;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \phi_1\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(t\_0, \cos \phi_2, \sin \phi_2 \cdot \sin \phi_1\right)\right) \cdot R\\
\end{array}
\end{array}
if phi2 < 0.14499999999999999Initial program 72.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6451.1
Applied rewrites51.1%
if 0.14499999999999999 < phi2 Initial program 78.1%
Taylor expanded in phi1 around 0
lift-cos.f6447.5
Applied rewrites47.5%
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
*-commutativeN/A
lower-fma.f64N/A
lift-cos.f64N/A
lift--.f64N/A
*-commutativeN/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f6447.5
Applied rewrites47.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- lambda1 lambda2))))
(if (<= phi1 -3.5e-5)
(* (- (/ PI 2.0) (asin (* (cos phi1) t_0))) R)
(* (acos (* t_0 (cos phi2))) R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double tmp;
if (phi1 <= -3.5e-5) {
tmp = ((((double) M_PI) / 2.0) - asin((cos(phi1) * t_0))) * R;
} else {
tmp = acos((t_0 * cos(phi2))) * R;
}
return tmp;
}
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 <= -3.5e-5) {
tmp = ((Math.PI / 2.0) - Math.asin((Math.cos(phi1) * t_0))) * R;
} else {
tmp = Math.acos((t_0 * Math.cos(phi2))) * R;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((lambda1 - lambda2)) tmp = 0 if phi1 <= -3.5e-5: tmp = ((math.pi / 2.0) - math.asin((math.cos(phi1) * t_0))) * R else: tmp = math.acos((t_0 * math.cos(phi2))) * R return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi1 <= -3.5e-5) tmp = Float64(Float64(Float64(pi / 2.0) - asin(Float64(cos(phi1) * t_0))) * R); else tmp = Float64(acos(Float64(t_0 * cos(phi2))) * R); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = cos((lambda1 - lambda2)); tmp = 0.0; if (phi1 <= -3.5e-5) tmp = ((pi / 2.0) - asin((cos(phi1) * t_0))) * R; else tmp = acos((t_0 * cos(phi2))) * R; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -3.5e-5], N[(N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[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}
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_1 \leq -3.5 \cdot 10^{-5}:\\
\;\;\;\;\left(\frac{\pi}{2} - \sin^{-1} \left(\cos \phi_1 \cdot t\_0\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(t\_0 \cdot \cos \phi_2\right) \cdot R\\
\end{array}
\end{array}
if phi1 < -3.4999999999999997e-5Initial program 79.7%
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 rewrites79.6%
Taylor expanded in phi2 around 0
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift--.f6449.6
Applied rewrites49.6%
if -3.4999999999999997e-5 < phi1 Initial program 71.5%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6450.5
Applied rewrites50.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (acos (* (cos phi1) (cos lambda2))) R)))
(if (<= lambda2 -6.0)
t_0
(if (<= lambda2 0.016) (* (acos (* (cos lambda1) (cos phi1))) R) t_0))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = acos((cos(phi1) * cos(lambda2))) * R;
double tmp;
if (lambda2 <= -6.0) {
tmp = t_0;
} else if (lambda2 <= 0.016) {
tmp = acos((cos(lambda1) * cos(phi1))) * R;
} else {
tmp = t_0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: tmp
t_0 = acos((cos(phi1) * cos(lambda2))) * r
if (lambda2 <= (-6.0d0)) then
tmp = t_0
else if (lambda2 <= 0.016d0) then
tmp = acos((cos(lambda1) * cos(phi1))) * r
else
tmp = t_0
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.acos((Math.cos(phi1) * Math.cos(lambda2))) * R;
double tmp;
if (lambda2 <= -6.0) {
tmp = t_0;
} else if (lambda2 <= 0.016) {
tmp = Math.acos((Math.cos(lambda1) * Math.cos(phi1))) * R;
} else {
tmp = t_0;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.acos((math.cos(phi1) * math.cos(lambda2))) * R tmp = 0 if lambda2 <= -6.0: tmp = t_0 elif lambda2 <= 0.016: tmp = math.acos((math.cos(lambda1) * math.cos(phi1))) * R else: tmp = t_0 return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(acos(Float64(cos(phi1) * cos(lambda2))) * R) tmp = 0.0 if (lambda2 <= -6.0) tmp = t_0; elseif (lambda2 <= 0.016) tmp = Float64(acos(Float64(cos(lambda1) * cos(phi1))) * R); else tmp = t_0; end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = acos((cos(phi1) * cos(lambda2))) * R; tmp = 0.0; if (lambda2 <= -6.0) tmp = t_0; elseif (lambda2 <= 0.016) tmp = acos((cos(lambda1) * cos(phi1))) * R; else tmp = t_0; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[lambda2, -6.0], t$95$0, If[LessEqual[lambda2, 0.016], N[(N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right) \cdot R\\
\mathbf{if}\;\lambda_2 \leq -6:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\lambda_2 \leq 0.016:\\
\;\;\;\;\cos^{-1} \left(\cos \lambda_1 \cdot \cos \phi_1\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if lambda2 < -6 or 0.016 < lambda2 Initial program 59.9%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6440.0
Applied rewrites40.0%
Taylor expanded in lambda1 around 0
cos-neg-revN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f6439.9
Applied rewrites39.9%
if -6 < lambda2 < 0.016Initial program 87.6%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6446.0
Applied rewrites46.0%
Taylor expanded in lambda1 around inf
Applied rewrites45.6%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- lambda1 lambda2))))
(if (<= phi2 0.145)
(* (acos (* t_0 (cos phi1))) R)
(* (acos (* t_0 (cos phi2))) R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double tmp;
if (phi2 <= 0.145) {
tmp = acos((t_0 * cos(phi1))) * R;
} else {
tmp = acos((t_0 * cos(phi2))) * R;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: tmp
t_0 = cos((lambda1 - lambda2))
if (phi2 <= 0.145d0) then
tmp = acos((t_0 * cos(phi1))) * r
else
tmp = acos((t_0 * cos(phi2))) * r
end if
code = tmp
end function
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 <= 0.145) {
tmp = Math.acos((t_0 * Math.cos(phi1))) * R;
} else {
tmp = Math.acos((t_0 * Math.cos(phi2))) * R;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((lambda1 - lambda2)) tmp = 0 if phi2 <= 0.145: tmp = math.acos((t_0 * math.cos(phi1))) * R else: tmp = math.acos((t_0 * math.cos(phi2))) * R return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi2 <= 0.145) tmp = Float64(acos(Float64(t_0 * cos(phi1))) * R); else tmp = Float64(acos(Float64(t_0 * cos(phi2))) * R); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = cos((lambda1 - lambda2)); tmp = 0.0; if (phi2 <= 0.145) tmp = acos((t_0 * cos(phi1))) * R; else tmp = acos((t_0 * cos(phi2))) * R; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 0.145], 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}
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq 0.145:\\
\;\;\;\;\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 < 0.14499999999999999Initial program 72.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6451.1
Applied rewrites51.1%
if 0.14499999999999999 < phi2 Initial program 78.1%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6448.0
Applied rewrites48.0%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi1 -0.00041) (* (acos (* (cos phi1) (cos lambda2))) R) (* (acos (cos (- lambda1 lambda2))) R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -0.00041) {
tmp = acos((cos(phi1) * cos(lambda2))) * R;
} else {
tmp = acos(cos((lambda1 - lambda2))) * R;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: tmp
if (phi1 <= (-0.00041d0)) then
tmp = acos((cos(phi1) * cos(lambda2))) * r
else
tmp = acos(cos((lambda1 - lambda2))) * r
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -0.00041) {
tmp = Math.acos((Math.cos(phi1) * Math.cos(lambda2))) * R;
} else {
tmp = Math.acos(Math.cos((lambda1 - lambda2))) * R;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi1 <= -0.00041: tmp = math.acos((math.cos(phi1) * math.cos(lambda2))) * R else: tmp = math.acos(math.cos((lambda1 - lambda2))) * R return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -0.00041) tmp = Float64(acos(Float64(cos(phi1) * cos(lambda2))) * R); else tmp = Float64(acos(cos(Float64(lambda1 - lambda2))) * R); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (phi1 <= -0.00041) tmp = acos((cos(phi1) * cos(lambda2))) * R; else tmp = acos(cos((lambda1 - lambda2))) * R; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -0.00041], N[(N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], N[(N[ArcCos[N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -0.00041:\\
\;\;\;\;\cos^{-1} \left(\cos \phi_1 \cdot \cos \lambda_2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R\\
\end{array}
\end{array}
if phi1 < -4.0999999999999999e-4Initial program 79.7%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6449.7
Applied rewrites49.7%
Taylor expanded in lambda1 around 0
cos-neg-revN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-cos.f6441.0
Applied rewrites41.0%
if -4.0999999999999999e-4 < phi1 Initial program 71.5%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6440.7
Applied rewrites40.7%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6429.8
Applied rewrites29.8%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* (acos (* (cos (- lambda1 lambda2)) (cos phi1))) R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos((cos((lambda1 - lambda2)) * cos(phi1))) * 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((cos((lambda1 - lambda2)) * cos(phi1))) * r
end function
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;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.acos((math.cos((lambda1 - lambda2)) * math.cos(phi1))) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(Float64(cos(Float64(lambda1 - lambda2)) * cos(phi1))) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = acos((cos((lambda1 - lambda2)) * cos(phi1))) * R; end
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}
\\
\cos^{-1} \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right) \cdot R
\end{array}
Initial program 73.5%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6442.9
Applied rewrites42.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (acos (cos lambda1)) R)))
(if (<= lambda1 -2.5e+27)
t_0
(if (<= lambda1 2.3e-15) (* (acos (cos lambda2)) R) t_0))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = acos(cos(lambda1)) * R;
double tmp;
if (lambda1 <= -2.5e+27) {
tmp = t_0;
} else if (lambda1 <= 2.3e-15) {
tmp = acos(cos(lambda2)) * R;
} else {
tmp = t_0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: tmp
t_0 = acos(cos(lambda1)) * r
if (lambda1 <= (-2.5d+27)) then
tmp = t_0
else if (lambda1 <= 2.3d-15) then
tmp = acos(cos(lambda2)) * r
else
tmp = t_0
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.acos(Math.cos(lambda1)) * R;
double tmp;
if (lambda1 <= -2.5e+27) {
tmp = t_0;
} else if (lambda1 <= 2.3e-15) {
tmp = Math.acos(Math.cos(lambda2)) * R;
} else {
tmp = t_0;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.acos(math.cos(lambda1)) * R tmp = 0 if lambda1 <= -2.5e+27: tmp = t_0 elif lambda1 <= 2.3e-15: tmp = math.acos(math.cos(lambda2)) * R else: tmp = t_0 return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(acos(cos(lambda1)) * R) tmp = 0.0 if (lambda1 <= -2.5e+27) tmp = t_0; elseif (lambda1 <= 2.3e-15) tmp = Float64(acos(cos(lambda2)) * R); else tmp = t_0; end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = acos(cos(lambda1)) * R; tmp = 0.0; if (lambda1 <= -2.5e+27) tmp = t_0; elseif (lambda1 <= 2.3e-15) tmp = acos(cos(lambda2)) * R; else tmp = t_0; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[ArcCos[N[Cos[lambda1], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]}, If[LessEqual[lambda1, -2.5e+27], t$95$0, If[LessEqual[lambda1, 2.3e-15], N[(N[ArcCos[N[Cos[lambda2], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \cos \lambda_1 \cdot R\\
\mathbf{if}\;\lambda_1 \leq -2.5 \cdot 10^{+27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\lambda_1 \leq 2.3 \cdot 10^{-15}:\\
\;\;\;\;\cos^{-1} \cos \lambda_2 \cdot R\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if lambda1 < -2.4999999999999999e27 or 2.2999999999999999e-15 < lambda1 Initial program 59.1%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6438.7
Applied rewrites38.7%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6429.3
Applied rewrites29.3%
Taylor expanded in lambda1 around 0
mul-1-negN/A
lower-neg.f6412.1
Applied rewrites12.1%
Taylor expanded in lambda1 around inf
Applied rewrites29.0%
if -2.4999999999999999e27 < lambda1 < 2.2999999999999999e-15Initial program 86.8%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6446.8
Applied rewrites46.8%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6423.8
Applied rewrites23.8%
Taylor expanded in lambda1 around 0
mul-1-negN/A
lower-neg.f6423.0
Applied rewrites23.0%
Taylor expanded in lambda1 around 0
cos-neg-revN/A
lift-cos.f6423.0
Applied rewrites23.0%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* (acos (cos (- lambda1 lambda2))) R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(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(cos((lambda1 - lambda2))) * r
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return Math.acos(Math.cos((lambda1 - lambda2))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.acos(math.cos((lambda1 - lambda2))) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(cos(Float64(lambda1 - lambda2))) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = acos(cos((lambda1 - lambda2))) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \cos \left(\lambda_1 - \lambda_2\right) \cdot R
\end{array}
Initial program 73.5%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6442.9
Applied rewrites42.9%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6426.4
Applied rewrites26.4%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* (acos (cos lambda2)) R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(cos(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(cos(lambda2)) * r
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return Math.acos(Math.cos(lambda2)) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.acos(math.cos(lambda2)) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(cos(lambda2)) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = acos(cos(lambda2)) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[Cos[lambda2], $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \cos \lambda_2 \cdot R
\end{array}
Initial program 73.5%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift-cos.f6442.9
Applied rewrites42.9%
Taylor expanded in phi1 around 0
lift-cos.f64N/A
lift--.f6426.4
Applied rewrites26.4%
Taylor expanded in lambda1 around 0
mul-1-negN/A
lower-neg.f6417.8
Applied rewrites17.8%
Taylor expanded in lambda1 around 0
cos-neg-revN/A
lift-cos.f6417.8
Applied rewrites17.8%
herbie shell --seed 2025097
(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))