
(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}
Sampling outcomes in binary64 precision:
Herbie found 10 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 63.1%
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-hypot.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6496.7
Applied rewrites96.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (- phi1 phi2) (- phi1 phi2)))
(t_1 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))))
(if (<= (* R (sqrt (+ (* t_1 t_1) t_0))) 5e+297)
(*
R
(sqrt
(+
(*
(* (- lambda1 lambda2) (- lambda1 lambda2))
(+ 0.5 (* 0.5 (cos (* 2.0 (/ (+ phi2 phi1) 2.0))))))
t_0)))
(* (hypot (- phi1 phi2) (- lambda1 lambda2)) R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (phi1 - phi2) * (phi1 - phi2);
double t_1 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
double tmp;
if ((R * sqrt(((t_1 * t_1) + t_0))) <= 5e+297) {
tmp = R * sqrt(((((lambda1 - lambda2) * (lambda1 - lambda2)) * (0.5 + (0.5 * cos((2.0 * ((phi2 + phi1) / 2.0)))))) + t_0));
} else {
tmp = hypot((phi1 - phi2), (lambda1 - lambda2)) * R;
}
return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (phi1 - phi2) * (phi1 - phi2);
double t_1 = (lambda1 - lambda2) * Math.cos(((phi1 + phi2) / 2.0));
double tmp;
if ((R * Math.sqrt(((t_1 * t_1) + t_0))) <= 5e+297) {
tmp = R * Math.sqrt(((((lambda1 - lambda2) * (lambda1 - lambda2)) * (0.5 + (0.5 * Math.cos((2.0 * ((phi2 + phi1) / 2.0)))))) + t_0));
} else {
tmp = Math.hypot((phi1 - phi2), (lambda1 - lambda2)) * R;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = (phi1 - phi2) * (phi1 - phi2) t_1 = (lambda1 - lambda2) * math.cos(((phi1 + phi2) / 2.0)) tmp = 0 if (R * math.sqrt(((t_1 * t_1) + t_0))) <= 5e+297: tmp = R * math.sqrt(((((lambda1 - lambda2) * (lambda1 - lambda2)) * (0.5 + (0.5 * math.cos((2.0 * ((phi2 + phi1) / 2.0)))))) + t_0)) else: tmp = math.hypot((phi1 - phi2), (lambda1 - lambda2)) * R return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2)) t_1 = Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0))) tmp = 0.0 if (Float64(R * sqrt(Float64(Float64(t_1 * t_1) + t_0))) <= 5e+297) tmp = Float64(R * sqrt(Float64(Float64(Float64(Float64(lambda1 - lambda2) * Float64(lambda1 - lambda2)) * Float64(0.5 + Float64(0.5 * cos(Float64(2.0 * Float64(Float64(phi2 + phi1) / 2.0)))))) + t_0))); else tmp = Float64(hypot(Float64(phi1 - phi2), Float64(lambda1 - lambda2)) * R); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = (phi1 - phi2) * (phi1 - phi2); t_1 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0)); tmp = 0.0; if ((R * sqrt(((t_1 * t_1) + t_0))) <= 5e+297) tmp = R * sqrt(((((lambda1 - lambda2) * (lambda1 - lambda2)) * (0.5 + (0.5 * cos((2.0 * ((phi2 + phi1) / 2.0)))))) + t_0)); else tmp = hypot((phi1 - phi2), (lambda1 - lambda2)) * R; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(R * N[Sqrt[N[(N[(t$95$1 * t$95$1), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e+297], N[(R * N[Sqrt[N[(N[(N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(0.5 * N[Cos[N[(2.0 * N[(N[(phi2 + phi1), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)\\
t_1 := \left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\\
\mathbf{if}\;R \cdot \sqrt{t\_1 \cdot t\_1 + t\_0} \leq 5 \cdot 10^{+297}:\\
\;\;\;\;R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot \left(0.5 + 0.5 \cdot \cos \left(2 \cdot \frac{\phi_2 + \phi_1}{2}\right)\right) + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \lambda_1 - \lambda_2\right) \cdot R\\
\end{array}
\end{array}
if (*.f64 R (sqrt.f64 (+.f64 (*.f64 (*.f64 (-.f64 lambda1 lambda2) (cos.f64 (/.f64 (+.f64 phi1 phi2) #s(literal 2 binary64)))) (*.f64 (-.f64 lambda1 lambda2) (cos.f64 (/.f64 (+.f64 phi1 phi2) #s(literal 2 binary64))))) (*.f64 (-.f64 phi1 phi2) (-.f64 phi1 phi2))))) < 4.9999999999999998e297Initial program 70.9%
swap-sqrN/A
unpow2N/A
lower-*.f64N/A
lower-pow.f64N/A
lower--.f64N/A
sqr-cos-aN/A
lower-+.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6470.9
Applied rewrites70.9%
unpow2N/A
lower-*.f64N/A
lower--.f64N/A
lower--.f6470.9
Applied rewrites70.9%
if 4.9999999999999998e297 < (*.f64 R (sqrt.f64 (+.f64 (*.f64 (*.f64 (-.f64 lambda1 lambda2) (cos.f64 (/.f64 (+.f64 phi1 phi2) #s(literal 2 binary64)))) (*.f64 (-.f64 lambda1 lambda2) (cos.f64 (/.f64 (+.f64 phi1 phi2) #s(literal 2 binary64))))) (*.f64 (-.f64 phi1 phi2) (-.f64 phi1 phi2))))) Initial program 48.9%
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-hypot.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6498.2
Applied rewrites98.2%
Taylor expanded in phi2 around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower--.f6483.0
Applied rewrites83.0%
Taylor expanded in phi1 around 0
lower--.f6483.5
Applied rewrites83.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= phi2 1.25e-79)
(* (hypot (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) phi1) R)
(if (or (<= phi2 4.5e+17) (not (<= phi2 7.5e+116)))
(* (hypot (- phi1 phi2) (- lambda1 lambda2)) R)
(* (hypot phi1 (* (cos (* 0.5 phi2)) (- lambda1 lambda2))) R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 1.25e-79) {
tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
} else if ((phi2 <= 4.5e+17) || !(phi2 <= 7.5e+116)) {
tmp = hypot((phi1 - phi2), (lambda1 - lambda2)) * R;
} else {
tmp = hypot(phi1, (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 <= 1.25e-79) {
tmp = Math.hypot((Math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
} else if ((phi2 <= 4.5e+17) || !(phi2 <= 7.5e+116)) {
tmp = Math.hypot((phi1 - phi2), (lambda1 - lambda2)) * R;
} else {
tmp = Math.hypot(phi1, (Math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi2 <= 1.25e-79: tmp = math.hypot((math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R elif (phi2 <= 4.5e+17) or not (phi2 <= 7.5e+116): tmp = math.hypot((phi1 - phi2), (lambda1 - lambda2)) * R else: tmp = math.hypot(phi1, (math.cos((0.5 * phi2)) * (lambda1 - lambda2))) * R return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 1.25e-79) tmp = Float64(hypot(Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1) * R); elseif ((phi2 <= 4.5e+17) || !(phi2 <= 7.5e+116)) tmp = Float64(hypot(Float64(phi1 - phi2), Float64(lambda1 - lambda2)) * R); else tmp = Float64(hypot(phi1, 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 <= 1.25e-79) tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R; elseif ((phi2 <= 4.5e+17) || ~((phi2 <= 7.5e+116))) tmp = hypot((phi1 - phi2), (lambda1 - lambda2)) * R; else tmp = hypot(phi1, (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1.25e-79], N[(N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision] * R), $MachinePrecision], If[Or[LessEqual[phi2, 4.5e+17], N[Not[LessEqual[phi2, 7.5e+116]], $MachinePrecision]], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[phi1 ^ 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 1.25 \cdot 10^{-79}:\\
\;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \cdot R\\
\mathbf{elif}\;\phi_2 \leq 4.5 \cdot 10^{+17} \lor \neg \left(\phi_2 \leq 7.5 \cdot 10^{+116}\right):\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \lambda_1 - \lambda_2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
\end{array}
\end{array}
if phi2 < 1.25e-79Initial program 61.9%
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-hypot.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6497.8
Applied rewrites97.8%
Taylor expanded in phi2 around 0
unpow-prod-downN/A
unpow2N/A
pow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower--.f6475.2
Applied rewrites75.2%
if 1.25e-79 < phi2 < 4.5e17 or 7.5e116 < phi2 Initial program 70.8%
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-hypot.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6497.7
Applied rewrites97.7%
Taylor expanded in phi2 around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower--.f6485.5
Applied rewrites85.5%
Taylor expanded in phi1 around 0
lower--.f6487.9
Applied rewrites87.9%
if 4.5e17 < phi2 < 7.5e116Initial program 56.1%
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-hypot.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6481.2
Applied rewrites81.2%
Taylor expanded in phi1 around 0
lower-*.f6481.4
Applied rewrites81.4%
Taylor expanded in phi1 around inf
Applied rewrites70.7%
Final simplification77.1%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 1.25e-79) (* (hypot (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) phi1) 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 <= 1.25e-79) {
tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * 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 <= 1.25e-79) {
tmp = Math.hypot((Math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * 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 <= 1.25e-79: tmp = math.hypot((math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * 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 <= 1.25e-79) tmp = Float64(hypot(Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1) * 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 <= 1.25e-79) tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * 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, 1.25e-79], N[(N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 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 1.25 \cdot 10^{-79}:\\
\;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\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 < 1.25e-79Initial program 61.9%
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-hypot.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6497.8
Applied rewrites97.8%
Taylor expanded in phi2 around 0
unpow-prod-downN/A
unpow2N/A
pow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower--.f6475.2
Applied rewrites75.2%
if 1.25e-79 < phi2 Initial program 66.8%
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-hypot.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6493.2
Applied rewrites93.2%
Taylor expanded in phi1 around 0
lower-*.f6489.2
Applied rewrites89.2%
Final simplification78.6%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 1.25e-79) (* (hypot (* (cos (* 0.5 phi1)) (- lambda1 lambda2)) phi1) R) (* (hypot (- phi1 phi2) (- lambda1 lambda2)) R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 1.25e-79) {
tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
} else {
tmp = hypot((phi1 - phi2), (lambda1 - lambda2)) * R;
}
return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 1.25e-79) {
tmp = Math.hypot((Math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R;
} else {
tmp = Math.hypot((phi1 - phi2), (lambda1 - lambda2)) * R;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi2 <= 1.25e-79: tmp = math.hypot((math.cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R else: tmp = math.hypot((phi1 - phi2), (lambda1 - lambda2)) * R return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 1.25e-79) tmp = Float64(hypot(Float64(cos(Float64(0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1) * R); else tmp = Float64(hypot(Float64(phi1 - phi2), Float64(lambda1 - lambda2)) * R); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (phi2 <= 1.25e-79) tmp = hypot((cos((0.5 * phi1)) * (lambda1 - lambda2)), phi1) * R; else tmp = hypot((phi1 - phi2), (lambda1 - lambda2)) * R; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1.25e-79], N[(N[Sqrt[N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 1.25 \cdot 10^{-79}:\\
\;\;\;\;\mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \lambda_1 - \lambda_2\right) \cdot R\\
\end{array}
\end{array}
if phi2 < 1.25e-79Initial program 61.9%
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-hypot.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6497.8
Applied rewrites97.8%
Taylor expanded in phi2 around 0
unpow-prod-downN/A
unpow2N/A
pow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower--.f6475.2
Applied rewrites75.2%
if 1.25e-79 < phi2 Initial program 66.8%
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-hypot.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6493.2
Applied rewrites93.2%
Taylor expanded in phi2 around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower--.f6471.4
Applied rewrites71.4%
Taylor expanded in phi1 around 0
lower--.f6475.9
Applied rewrites75.9%
Final simplification75.4%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= lambda2 1.2e+215) (* (hypot (- phi1 phi2) (- lambda1 lambda2)) R) (* R (* lambda2 (sqrt (+ 0.5 (* 0.5 (cos (+ phi1 phi2)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda2 <= 1.2e+215) {
tmp = hypot((phi1 - phi2), (lambda1 - lambda2)) * R;
} else {
tmp = R * (lambda2 * sqrt((0.5 + (0.5 * cos((phi1 + phi2))))));
}
return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda2 <= 1.2e+215) {
tmp = Math.hypot((phi1 - phi2), (lambda1 - lambda2)) * R;
} else {
tmp = R * (lambda2 * Math.sqrt((0.5 + (0.5 * Math.cos((phi1 + phi2))))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if lambda2 <= 1.2e+215: tmp = math.hypot((phi1 - phi2), (lambda1 - lambda2)) * R else: tmp = R * (lambda2 * math.sqrt((0.5 + (0.5 * math.cos((phi1 + phi2)))))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (lambda2 <= 1.2e+215) tmp = Float64(hypot(Float64(phi1 - phi2), Float64(lambda1 - lambda2)) * R); else tmp = Float64(R * Float64(lambda2 * sqrt(Float64(0.5 + Float64(0.5 * cos(Float64(phi1 + phi2))))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (lambda2 <= 1.2e+215) tmp = hypot((phi1 - phi2), (lambda1 - lambda2)) * R; else tmp = R * (lambda2 * sqrt((0.5 + (0.5 * cos((phi1 + phi2)))))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 1.2e+215], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(R * N[(lambda2 * N[Sqrt[N[(0.5 + N[(0.5 * N[Cos[N[(phi1 + phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 1.2 \cdot 10^{+215}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \lambda_1 - \lambda_2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\lambda_2 \cdot \sqrt{0.5 + 0.5 \cdot \cos \left(\phi_1 + \phi_2\right)}\right)\\
\end{array}
\end{array}
if lambda2 < 1.2e215Initial program 64.0%
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-hypot.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6496.7
Applied rewrites96.7%
Taylor expanded in phi2 around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower--.f6483.2
Applied rewrites83.2%
Taylor expanded in phi1 around 0
lower--.f6483.6
Applied rewrites83.6%
if 1.2e215 < lambda2 Initial program 52.6%
swap-sqrN/A
unpow2N/A
lower-*.f64N/A
lower-pow.f64N/A
lower--.f64N/A
sqr-cos-aN/A
lower-+.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6452.6
Applied rewrites52.6%
Taylor expanded in lambda2 around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-+.f6477.7
Applied rewrites77.7%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* (hypot (- phi1 phi2) (- lambda1 lambda2)) R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return hypot((phi1 - phi2), (lambda1 - lambda2)) * R;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return Math.hypot((phi1 - phi2), (lambda1 - lambda2)) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.hypot((phi1 - phi2), (lambda1 - lambda2)) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(hypot(Float64(phi1 - phi2), Float64(lambda1 - lambda2)) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = hypot((phi1 - phi2), (lambda1 - lambda2)) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(lambda1 - lambda2), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{hypot}\left(\phi_1 - \phi_2, \lambda_1 - \lambda_2\right) \cdot R
\end{array}
Initial program 63.1%
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-hypot.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6496.7
Applied rewrites96.7%
Taylor expanded in phi2 around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower--.f6482.8
Applied rewrites82.8%
Taylor expanded in phi1 around 0
lower--.f6482.8
Applied rewrites82.8%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi1 -3.2e-55) (* R (- phi1)) (* R phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -3.2e-55) {
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 (phi1 <= (-3.2d-55)) 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 (phi1 <= -3.2e-55) {
tmp = R * -phi1;
} else {
tmp = R * phi2;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi1 <= -3.2e-55: tmp = R * -phi1 else: tmp = R * phi2 return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -3.2e-55) 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 (phi1 <= -3.2e-55) tmp = R * -phi1; else tmp = R * phi2; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -3.2e-55], N[(R * (-phi1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -3.2 \cdot 10^{-55}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \phi_2\\
\end{array}
\end{array}
if phi1 < -3.2000000000000001e-55Initial program 60.7%
Taylor expanded in phi1 around -inf
mul-1-negN/A
lower-neg.f6450.8
Applied rewrites50.8%
if -3.2000000000000001e-55 < phi1 Initial program 64.2%
Taylor expanded in phi2 around inf
Applied rewrites14.7%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R (- phi2 phi1)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (phi2 - 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 * (phi2 - phi1)
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (phi2 - phi1);
}
def code(R, lambda1, lambda2, phi1, phi2): return R * (phi2 - phi1)
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * Float64(phi2 - phi1)) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * (phi2 - phi1); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \left(\phi_2 - \phi_1\right)
\end{array}
Initial program 63.1%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6424.8
Applied rewrites24.8%
Taylor expanded in phi1 around 0
lower-+.f64N/A
lower-*.f6426.0
Applied rewrites26.0%
Final simplification26.0%
(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 63.1%
Taylor expanded in phi2 around inf
Applied rewrites12.6%
herbie shell --seed 2025044
(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))))))