
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (let* ((t_0 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))))) (* R (sqrt (+ (* t_0 t_0) (* (- phi1 phi2) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
return R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0d0))
code = r * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda1 - lambda2) * Math.cos(((phi1 + phi2) / 2.0));
return R * Math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = (lambda1 - lambda2) * math.cos(((phi1 + phi2) / 2.0)) return R * math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0))) return Float64(R * sqrt(Float64(Float64(t_0 * t_0) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0)); tmp = R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2)))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(R * N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\
R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}
\end{array}
\end{array}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (let* ((t_0 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))))) (* R (sqrt (+ (* t_0 t_0) (* (- phi1 phi2) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
return R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0d0))
code = r * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda1 - lambda2) * Math.cos(((phi1 + phi2) / 2.0));
return R * Math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = (lambda1 - lambda2) * math.cos(((phi1 + phi2) / 2.0)) return R * math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0))) return Float64(R * sqrt(Float64(Float64(t_0 * t_0) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0)); tmp = R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2)))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(R * N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\
R \cdot \sqrt{t\_0 \cdot t\_0 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}
\end{array}
\end{array}
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* (hypot (- phi1 phi2) (* (cos (/ (+ phi2 phi1) 2.0)) (- lambda1 lambda2))) R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return hypot((phi1 - phi2), (cos(((phi2 + phi1) / 2.0)) * (lambda1 - lambda2))) * R;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return Math.hypot((phi1 - phi2), (Math.cos(((phi2 + phi1) / 2.0)) * (lambda1 - lambda2))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.hypot((phi1 - phi2), (math.cos(((phi2 + phi1) / 2.0)) * (lambda1 - lambda2))) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(Float64(phi2 + phi1) / 2.0)) * Float64(lambda1 - lambda2))) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = hypot((phi1 - phi2), (cos(((phi2 + phi1) / 2.0)) * (lambda1 - lambda2))) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(N[(phi2 + phi1), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(\frac{\phi_2 + \phi_1}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\end{array}
Initial program 60.3%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites96.4%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 0.00185) (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R) (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi2)) (- lambda1 lambda2))) R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 0.00185) {
tmp = hypot((phi1 - phi2), (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
} else {
tmp = hypot((phi1 - phi2), (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
}
return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 0.00185) {
tmp = Math.hypot((phi1 - phi2), (Math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
} else {
tmp = Math.hypot((phi1 - phi2), (Math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi2 <= 0.00185: tmp = math.hypot((phi1 - phi2), (math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R else: tmp = math.hypot((phi1 - phi2), (math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 0.00185) tmp = Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R); else tmp = Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(0.5 * phi2)) * Float64(lambda1 - lambda2))) * R); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (phi2 <= 0.00185) tmp = hypot((phi1 - phi2), (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R; else tmp = hypot((phi1 - phi2), (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 0.00185], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 0.00185:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
\end{array}
\end{array}
if phi2 < 0.0018500000000000001Initial program 62.3%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites97.7%
Taylor expanded in phi1 around inf
lower-*.f6493.9
Applied rewrites93.9%
if 0.0018500000000000001 < phi2 Initial program 54.5%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites92.5%
Taylor expanded in phi1 around 0
lower-*.f6492.3
Applied rewrites92.3%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return hypot((phi1 - phi2), (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return Math.hypot((phi1 - phi2), (Math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.hypot((phi1 - phi2), (math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = hypot((phi1 - phi2), (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\end{array}
Initial program 60.3%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites96.4%
Taylor expanded in phi1 around inf
lower-*.f6490.7
Applied rewrites90.7%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 1e-13) (* (hypot phi1 (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R) (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi2)) lambda1)) R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 1e-13) {
tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
} else {
tmp = hypot((phi1 - phi2), (cos((0.5 * phi2)) * lambda1)) * R;
}
return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 1e-13) {
tmp = Math.hypot(phi1, (Math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
} else {
tmp = Math.hypot((phi1 - phi2), (Math.cos((0.5 * phi2)) * lambda1)) * R;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi2 <= 1e-13: tmp = math.hypot(phi1, (math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R else: tmp = math.hypot((phi1 - phi2), (math.cos((0.5 * phi2)) * lambda1)) * R return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 1e-13) tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R); else tmp = Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(0.5 * phi2)) * lambda1)) * R); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (phi2 <= 1e-13) tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R; else tmp = hypot((phi1 - phi2), (cos((0.5 * phi2)) * lambda1)) * R; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1e-13], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 10^{-13}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1\right) \cdot R\\
\end{array}
\end{array}
if phi2 < 1e-13Initial program 62.3%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites97.8%
Taylor expanded in phi1 around inf
lower-*.f6494.0
Applied rewrites94.0%
Taylor expanded in phi1 around inf
Applied rewrites79.5%
if 1e-13 < phi2 Initial program 54.5%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites92.4%
Taylor expanded in phi1 around 0
lower-*.f6492.0
Applied rewrites92.0%
Taylor expanded in lambda1 around inf
Applied rewrites83.4%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 1e-13) (* (hypot phi1 (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R) (* (- phi2 (* 1.0 phi1)) R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 1e-13) {
tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
} else {
tmp = (phi2 - (1.0 * phi1)) * R;
}
return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 1e-13) {
tmp = Math.hypot(phi1, (Math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
} else {
tmp = (phi2 - (1.0 * phi1)) * R;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi2 <= 1e-13: tmp = math.hypot(phi1, (math.cos((0.5 * phi1)) * (lambda1 - lambda2))) * R else: tmp = (phi2 - (1.0 * phi1)) * R return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 1e-13) tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2))) * R); else tmp = Float64(Float64(phi2 - Float64(1.0 * phi1)) * R); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (phi2 <= 1e-13) tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R; else tmp = (phi2 - (1.0 * phi1)) * R; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1e-13], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[(phi2 - N[(1.0 * phi1), $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 10^{-13}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\left(\phi_2 - 1 \cdot \phi_1\right) \cdot R\\
\end{array}
\end{array}
if phi2 < 1e-13Initial program 62.3%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites97.8%
Taylor expanded in phi1 around inf
lower-*.f6494.0
Applied rewrites94.0%
Taylor expanded in phi1 around inf
Applied rewrites79.5%
if 1e-13 < phi2 Initial program 54.5%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites92.4%
Taylor expanded in phi1 around inf
lower-*.f6481.6
Applied rewrites81.6%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6462.5
Applied rewrites62.5%
Taylor expanded in phi1 around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f64N/A
lower-*.f6462.5
Applied rewrites62.5%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= lambda2 3e+168) (* (- phi2 (* 1.0 phi1)) R) (* R (* (cos (* 0.5 (+ phi2 phi1))) lambda2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda2 <= 3e+168) {
tmp = (phi2 - (1.0 * phi1)) * R;
} else {
tmp = R * (cos((0.5 * (phi2 + phi1))) * lambda2);
}
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 (lambda2 <= 3d+168) then
tmp = (phi2 - (1.0d0 * phi1)) * r
else
tmp = r * (cos((0.5d0 * (phi2 + phi1))) * lambda2)
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda2 <= 3e+168) {
tmp = (phi2 - (1.0 * phi1)) * R;
} else {
tmp = R * (Math.cos((0.5 * (phi2 + phi1))) * lambda2);
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if lambda2 <= 3e+168: tmp = (phi2 - (1.0 * phi1)) * R else: tmp = R * (math.cos((0.5 * (phi2 + phi1))) * lambda2) return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (lambda2 <= 3e+168) tmp = Float64(Float64(phi2 - Float64(1.0 * phi1)) * R); else tmp = Float64(R * Float64(cos(Float64(0.5 * Float64(phi2 + phi1))) * lambda2)); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (lambda2 <= 3e+168) tmp = (phi2 - (1.0 * phi1)) * R; else tmp = R * (cos((0.5 * (phi2 + phi1))) * lambda2); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 3e+168], N[(N[(phi2 - N[(1.0 * phi1), $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], N[(R * N[(N[Cos[N[(0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * lambda2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 3 \cdot 10^{+168}:\\
\;\;\;\;\left(\phi_2 - 1 \cdot \phi_1\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right) \cdot \lambda_2\right)\\
\end{array}
\end{array}
if lambda2 < 2.9999999999999998e168Initial program 62.3%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites96.8%
Taylor expanded in phi1 around inf
lower-*.f6491.7
Applied rewrites91.7%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6429.1
Applied rewrites29.1%
Taylor expanded in phi1 around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f64N/A
lower-*.f6431.7
Applied rewrites31.7%
if 2.9999999999999998e168 < lambda2 Initial program 43.6%
Taylor expanded in lambda2 around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6447.8
Applied rewrites47.8%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= R 2e+63) (* (- phi2 (* 1.0 phi1)) R) (* (- phi2) (fma R (/ phi1 phi2) (- R)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (R <= 2e+63) {
tmp = (phi2 - (1.0 * phi1)) * R;
} else {
tmp = -phi2 * fma(R, (phi1 / phi2), -R);
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (R <= 2e+63) tmp = Float64(Float64(phi2 - Float64(1.0 * phi1)) * R); else tmp = Float64(Float64(-phi2) * fma(R, Float64(phi1 / phi2), Float64(-R))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[R, 2e+63], N[(N[(phi2 - N[(1.0 * phi1), $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], N[((-phi2) * N[(R * N[(phi1 / phi2), $MachinePrecision] + (-R)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;R \leq 2 \cdot 10^{+63}:\\
\;\;\;\;\left(\phi_2 - 1 \cdot \phi_1\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\left(-\phi_2\right) \cdot \mathsf{fma}\left(R, \frac{\phi_1}{\phi_2}, -R\right)\\
\end{array}
\end{array}
if R < 2.00000000000000012e63Initial program 51.8%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites95.7%
Taylor expanded in phi1 around inf
lower-*.f6489.0
Applied rewrites89.0%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6427.0
Applied rewrites27.0%
Taylor expanded in phi1 around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f64N/A
lower-*.f6430.0
Applied rewrites30.0%
if 2.00000000000000012e63 < R Initial program 94.0%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6432.7
Applied rewrites32.7%
Taylor expanded in phi2 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
mul-1-negN/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6432.8
Applied rewrites32.8%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= R 2e+63) (* (- phi2 (* 1.0 phi1)) R) (* (+ (/ (- (* phi1 R)) phi2) R) phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (R <= 2e+63) {
tmp = (phi2 - (1.0 * phi1)) * R;
} else {
tmp = ((-(phi1 * R) / phi2) + R) * phi2;
}
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 (r <= 2d+63) then
tmp = (phi2 - (1.0d0 * phi1)) * r
else
tmp = ((-(phi1 * r) / phi2) + r) * phi2
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (R <= 2e+63) {
tmp = (phi2 - (1.0 * phi1)) * R;
} else {
tmp = ((-(phi1 * R) / phi2) + R) * phi2;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if R <= 2e+63: tmp = (phi2 - (1.0 * phi1)) * R else: tmp = ((-(phi1 * R) / phi2) + R) * phi2 return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (R <= 2e+63) tmp = Float64(Float64(phi2 - Float64(1.0 * phi1)) * R); else tmp = Float64(Float64(Float64(Float64(-Float64(phi1 * R)) / phi2) + R) * phi2); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (R <= 2e+63) tmp = (phi2 - (1.0 * phi1)) * R; else tmp = ((-(phi1 * R) / phi2) + R) * phi2; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[R, 2e+63], N[(N[(phi2 - N[(1.0 * phi1), $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], N[(N[(N[((-N[(phi1 * R), $MachinePrecision]) / phi2), $MachinePrecision] + R), $MachinePrecision] * phi2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;R \leq 2 \cdot 10^{+63}:\\
\;\;\;\;\left(\phi_2 - 1 \cdot \phi_1\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{-\phi_1 \cdot R}{\phi_2} + R\right) \cdot \phi_2\\
\end{array}
\end{array}
if R < 2.00000000000000012e63Initial program 51.8%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites95.7%
Taylor expanded in phi1 around inf
lower-*.f6489.0
Applied rewrites89.0%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6427.0
Applied rewrites27.0%
Taylor expanded in phi1 around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f64N/A
lower-*.f6430.0
Applied rewrites30.0%
if 2.00000000000000012e63 < R Initial program 94.0%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6433.2
Applied rewrites33.2%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= R 2e+162) (* (- phi2 (* 1.0 phi1)) R) (* (fma R (/ phi2 phi1) (- R)) phi1)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (R <= 2e+162) {
tmp = (phi2 - (1.0 * phi1)) * R;
} else {
tmp = fma(R, (phi2 / phi1), -R) * phi1;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (R <= 2e+162) tmp = Float64(Float64(phi2 - Float64(1.0 * phi1)) * R); else tmp = Float64(fma(R, Float64(phi2 / phi1), Float64(-R)) * phi1); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[R, 2e+162], N[(N[(phi2 - N[(1.0 * phi1), $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision], N[(N[(R * N[(phi2 / phi1), $MachinePrecision] + (-R)), $MachinePrecision] * phi1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;R \leq 2 \cdot 10^{+162}:\\
\;\;\;\;\left(\phi_2 - 1 \cdot \phi_1\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\right) \cdot \phi_1\\
\end{array}
\end{array}
if R < 1.9999999999999999e162Initial program 55.0%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites95.9%
Taylor expanded in phi1 around inf
lower-*.f6489.5
Applied rewrites89.5%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6426.9
Applied rewrites26.9%
Taylor expanded in phi1 around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f64N/A
lower-*.f6429.6
Applied rewrites29.6%
if 1.9999999999999999e162 < R Initial program 99.5%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6437.9
Applied rewrites37.9%
Taylor expanded in phi1 around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6437.8
Applied rewrites37.8%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* (- phi2 (* 1.0 phi1)) R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return (phi2 - (1.0 * 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 = (phi2 - (1.0d0 * phi1)) * r
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return (phi2 - (1.0 * phi1)) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return (phi2 - (1.0 * phi1)) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(Float64(phi2 - Float64(1.0 * phi1)) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = (phi2 - (1.0 * phi1)) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[(phi2 - N[(1.0 * phi1), $MachinePrecision]), $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
\\
\left(\phi_2 - 1 \cdot \phi_1\right) \cdot R
\end{array}
Initial program 60.3%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites96.4%
Taylor expanded in phi1 around inf
lower-*.f6490.7
Applied rewrites90.7%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6427.9
Applied rewrites27.9%
Taylor expanded in phi1 around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f64N/A
lower-*.f6430.3
Applied rewrites30.3%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 180000.0) (* R (- phi1)) (* R phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 180000.0) {
tmp = R * -phi1;
} else {
tmp = R * phi2;
}
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 (phi2 <= 180000.0d0) then
tmp = r * -phi1
else
tmp = r * phi2
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 180000.0) {
tmp = R * -phi1;
} else {
tmp = R * phi2;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi2 <= 180000.0: tmp = R * -phi1 else: tmp = R * phi2 return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 180000.0) tmp = Float64(R * Float64(-phi1)); else tmp = Float64(R * phi2); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (phi2 <= 180000.0) tmp = R * -phi1; else tmp = R * phi2; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 180000.0], N[(R * (-phi1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 180000:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \phi_2\\
\end{array}
\end{array}
if phi2 < 1.8e5Initial program 62.2%
Taylor expanded in phi1 around -inf
mul-1-negN/A
lower-neg.f6419.3
Applied rewrites19.3%
if 1.8e5 < phi2 Initial program 54.3%
Taylor expanded in phi2 around inf
Applied rewrites60.5%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi2))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * phi2;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * phi2
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * phi2;
}
def code(R, lambda1, lambda2, phi1, phi2): return R * phi2
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * phi2) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * phi2; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi2), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \phi_2
\end{array}
Initial program 60.3%
Taylor expanded in phi2 around inf
Applied rewrites17.7%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi1))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * phi1;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * phi1
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * phi1;
}
def code(R, lambda1, lambda2, phi1, phi2): return R * phi1
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * phi1) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * phi1; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi1), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \phi_1
\end{array}
Initial program 60.3%
Taylor expanded in phi1 around inf
Applied rewrites17.6%
herbie shell --seed 2025114
(FPCore (R lambda1 lambda2 phi1 phi2)
:name "Equirectangular approximation to distance on a great circle"
:precision binary64
(* R (sqrt (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))) (* (- phi1 phi2) (- phi1 phi2))))))