
(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 16 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 59.9%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites95.9%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi1 -0.32) (* (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 (phi1 <= -0.32) {
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 (phi1 <= -0.32) {
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 phi1 <= -0.32: 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 (phi1 <= -0.32) 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 (phi1 <= -0.32) 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[phi1, -0.32], 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_1 \leq -0.32:\\
\;\;\;\;\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 phi1 < -0.320000000000000007Initial program 52.4%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites92.3%
Taylor expanded in phi1 around inf
lower-*.f6492.2
Applied rewrites92.2%
if -0.320000000000000007 < phi1 Initial program 62.3%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites97.0%
Taylor expanded in phi1 around 0
lift-*.f6493.4
Applied rewrites93.4%
(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 59.9%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites95.9%
Taylor expanded in phi1 around inf
lower-*.f6490.2
Applied rewrites90.2%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (* 0.5 phi1))))
(if (<= lambda1 -4.1e+36)
(* (hypot (- phi1 phi2) (* t_0 lambda1)) R)
(* (hypot (- phi1 phi2) (* t_0 (- lambda2))) R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((0.5 * phi1));
double tmp;
if (lambda1 <= -4.1e+36) {
tmp = hypot((phi1 - phi2), (t_0 * lambda1)) * R;
} else {
tmp = hypot((phi1 - phi2), (t_0 * -lambda2)) * R;
}
return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.cos((0.5 * phi1));
double tmp;
if (lambda1 <= -4.1e+36) {
tmp = Math.hypot((phi1 - phi2), (t_0 * lambda1)) * R;
} else {
tmp = Math.hypot((phi1 - phi2), (t_0 * -lambda2)) * R;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((0.5 * phi1)) tmp = 0 if lambda1 <= -4.1e+36: tmp = math.hypot((phi1 - phi2), (t_0 * lambda1)) * R else: tmp = math.hypot((phi1 - phi2), (t_0 * -lambda2)) * R return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(0.5 * phi1)) tmp = 0.0 if (lambda1 <= -4.1e+36) tmp = Float64(hypot(Float64(phi1 - phi2), Float64(t_0 * lambda1)) * R); else tmp = Float64(hypot(Float64(phi1 - phi2), Float64(t_0 * Float64(-lambda2))) * R); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = cos((0.5 * phi1)); tmp = 0.0; if (lambda1 <= -4.1e+36) tmp = hypot((phi1 - phi2), (t_0 * lambda1)) * R; else tmp = hypot((phi1 - phi2), (t_0 * -lambda2)) * R; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda1, -4.1e+36], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(t$95$0 * lambda1), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(t$95$0 * (-lambda2)), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(0.5 \cdot \phi_1\right)\\
\mathbf{if}\;\lambda_1 \leq -4.1 \cdot 10^{+36}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \lambda_1\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, t\_0 \cdot \left(-\lambda_2\right)\right) \cdot R\\
\end{array}
\end{array}
if lambda1 < -4.10000000000000013e36Initial program 51.7%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites93.7%
Taylor expanded in phi1 around inf
lower-*.f6485.4
Applied rewrites85.4%
Taylor expanded in lambda1 around inf
Applied rewrites76.8%
if -4.10000000000000013e36 < lambda1 Initial program 62.2%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites96.5%
Taylor expanded in phi1 around inf
lower-*.f6491.6
Applied rewrites91.6%
Taylor expanded in lambda1 around 0
mul-1-negN/A
lower-neg.f6479.8
Applied rewrites79.8%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= lambda2 7.8e+40) (* (hypot (- phi1 phi2) (* (cos (* 0.5 phi1)) lambda1)) 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 (lambda2 <= 7.8e+40) {
tmp = hypot((phi1 - phi2), (cos((0.5 * phi1)) * lambda1)) * 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 (lambda2 <= 7.8e+40) {
tmp = Math.hypot((phi1 - phi2), (Math.cos((0.5 * phi1)) * lambda1)) * 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 lambda2 <= 7.8e+40: tmp = math.hypot((phi1 - phi2), (math.cos((0.5 * phi1)) * lambda1)) * 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 (lambda2 <= 7.8e+40) tmp = Float64(hypot(Float64(phi1 - phi2), Float64(cos(Float64(0.5 * phi1)) * lambda1)) * 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 (lambda2 <= 7.8e+40) tmp = hypot((phi1 - phi2), (cos((0.5 * phi1)) * lambda1)) * 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[lambda2, 7.8e+40], N[(N[Sqrt[N[(phi1 - phi2), $MachinePrecision] ^ 2 + N[(N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * lambda1), $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}\;\lambda_2 \leq 7.8 \cdot 10^{+40}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1 - \phi_2, \cos \left(0.5 \cdot \phi_1\right) \cdot \lambda_1\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 lambda2 < 7.8000000000000002e40Initial program 61.6%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites96.5%
Taylor expanded in phi1 around inf
lower-*.f6491.5
Applied rewrites91.5%
Taylor expanded in lambda1 around inf
Applied rewrites80.6%
if 7.8000000000000002e40 < lambda2 Initial program 53.7%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites93.6%
Taylor expanded in phi1 around 0
lift-*.f6485.5
Applied rewrites85.5%
Taylor expanded in phi1 around inf
Applied rewrites74.6%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 9.2e+168) (* (hypot phi1 (* (cos (* 0.5 phi2)) (- lambda1 lambda2))) R) (fma (- R) phi1 (* R phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 9.2e+168) {
tmp = hypot(phi1, (cos((0.5 * phi2)) * (lambda1 - lambda2))) * R;
} else {
tmp = fma(-R, phi1, (R * phi2));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 9.2e+168) tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi2)) * Float64(lambda1 - lambda2))) * R); else tmp = fma(Float64(-R), phi1, Float64(R * phi2)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 9.2e+168], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 9.2 \cdot 10^{+168}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
\end{array}
\end{array}
if phi2 < 9.1999999999999997e168Initial program 61.9%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites96.1%
Taylor expanded in phi1 around 0
lift-*.f6490.1
Applied rewrites90.1%
Taylor expanded in phi1 around inf
Applied rewrites73.8%
if 9.1999999999999997e168 < phi2 Initial program 43.9%
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-*.f6477.1
Applied rewrites77.1%
Taylor expanded in phi1 around 0
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6482.5
Applied rewrites82.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (* 0.5 phi2))))
(if (<= lambda2 -8.4e-271)
(* (hypot phi1 (* t_0 lambda1)) R)
(if (<= lambda2 7.8e+40)
(fma (- R) phi1 (* R phi2))
(* (hypot phi1 (* t_0 (- lambda2))) R)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((0.5 * phi2));
double tmp;
if (lambda2 <= -8.4e-271) {
tmp = hypot(phi1, (t_0 * lambda1)) * R;
} else if (lambda2 <= 7.8e+40) {
tmp = fma(-R, phi1, (R * phi2));
} else {
tmp = hypot(phi1, (t_0 * -lambda2)) * R;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(0.5 * phi2)) tmp = 0.0 if (lambda2 <= -8.4e-271) tmp = Float64(hypot(phi1, Float64(t_0 * lambda1)) * R); elseif (lambda2 <= 7.8e+40) tmp = fma(Float64(-R), phi1, Float64(R * phi2)); else tmp = Float64(hypot(phi1, Float64(t_0 * Float64(-lambda2))) * R); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda2, -8.4e-271], N[(N[Sqrt[phi1 ^ 2 + N[(t$95$0 * lambda1), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[lambda2, 7.8e+40], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[phi1 ^ 2 + N[(t$95$0 * (-lambda2)), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(0.5 \cdot \phi_2\right)\\
\mathbf{if}\;\lambda_2 \leq -8.4 \cdot 10^{-271}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, t\_0 \cdot \lambda_1\right) \cdot R\\
\mathbf{elif}\;\lambda_2 \leq 7.8 \cdot 10^{+40}:\\
\;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, t\_0 \cdot \left(-\lambda_2\right)\right) \cdot R\\
\end{array}
\end{array}
if lambda2 < -8.4000000000000003e-271Initial program 59.8%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites95.9%
Taylor expanded in phi1 around 0
lift-*.f6490.8
Applied rewrites90.8%
Taylor expanded in phi1 around inf
Applied rewrites70.7%
Taylor expanded in lambda1 around inf
Applied rewrites53.3%
if -8.4000000000000003e-271 < lambda2 < 7.8000000000000002e40Initial program 64.2%
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-*.f6434.6
Applied rewrites34.6%
Taylor expanded in phi1 around 0
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6436.0
Applied rewrites36.0%
if 7.8000000000000002e40 < lambda2 Initial program 53.7%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites93.6%
Taylor expanded in phi1 around 0
lift-*.f6485.5
Applied rewrites85.5%
Taylor expanded in phi1 around inf
Applied rewrites74.6%
Taylor expanded in lambda1 around 0
mul-1-negN/A
lower-neg.f6466.1
Applied rewrites66.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= phi2 -8.5e-222)
(* (hypot phi1 (* (cos (* 0.5 phi2)) lambda1)) R)
(if (<= phi2 2.4e+141)
(*
R
(sqrt
(+
(* (- lambda1 lambda2) (- lambda1 lambda2))
(* (- phi1 phi2) (- phi1 phi2)))))
(fma (- R) phi1 (* R phi2)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= -8.5e-222) {
tmp = hypot(phi1, (cos((0.5 * phi2)) * lambda1)) * R;
} else if (phi2 <= 2.4e+141) {
tmp = R * sqrt((((lambda1 - lambda2) * (lambda1 - lambda2)) + ((phi1 - phi2) * (phi1 - phi2))));
} else {
tmp = fma(-R, phi1, (R * phi2));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= -8.5e-222) tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi2)) * lambda1)) * R); elseif (phi2 <= 2.4e+141) tmp = Float64(R * sqrt(Float64(Float64(Float64(lambda1 - lambda2) * Float64(lambda1 - lambda2)) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2))))); else tmp = fma(Float64(-R), phi1, Float64(R * phi2)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, -8.5e-222], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], If[LessEqual[phi2, 2.4e+141], N[(R * N[Sqrt[N[(N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq -8.5 \cdot 10^{-222}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1\right) \cdot R\\
\mathbf{elif}\;\phi_2 \leq 2.4 \cdot 10^{+141}:\\
\;\;\;\;R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
\end{array}
\end{array}
if phi2 < -8.5000000000000003e-222Initial program 59.0%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites95.3%
Taylor expanded in phi1 around 0
lift-*.f6491.0
Applied rewrites91.0%
Taylor expanded in phi1 around inf
Applied rewrites66.4%
Taylor expanded in lambda1 around inf
Applied rewrites50.6%
if -8.5000000000000003e-222 < phi2 < 2.39999999999999997e141Initial program 65.4%
Taylor expanded in phi1 around 0
lower-*.f64N/A
unpow2N/A
sqr-cos-aN/A
lower-+.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lift--.f64N/A
lift--.f6463.5
Applied rewrites63.5%
Taylor expanded in phi2 around 0
pow2N/A
lift--.f64N/A
lift--.f64N/A
lift-*.f6461.8
Applied rewrites61.8%
if 2.39999999999999997e141 < phi2 Initial program 44.4%
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-*.f6474.3
Applied rewrites74.3%
Taylor expanded in phi1 around 0
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6479.7
Applied rewrites79.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= phi1 -3.7e+155)
(* R (* (- phi1) (+ (/ (- phi2) phi1) 1.0)))
(*
R
(sqrt
(+
(* (- lambda1 lambda2) (- lambda1 lambda2))
(* (- phi1 phi2) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -3.7e+155) {
tmp = R * (-phi1 * ((-phi2 / phi1) + 1.0));
} else {
tmp = R * sqrt((((lambda1 - lambda2) * (lambda1 - lambda2)) + ((phi1 - phi2) * (phi1 - 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.7d+155)) then
tmp = r * (-phi1 * ((-phi2 / phi1) + 1.0d0))
else
tmp = r * sqrt((((lambda1 - lambda2) * (lambda1 - lambda2)) + ((phi1 - phi2) * (phi1 - 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.7e+155) {
tmp = R * (-phi1 * ((-phi2 / phi1) + 1.0));
} else {
tmp = R * Math.sqrt((((lambda1 - lambda2) * (lambda1 - lambda2)) + ((phi1 - phi2) * (phi1 - phi2))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi1 <= -3.7e+155: tmp = R * (-phi1 * ((-phi2 / phi1) + 1.0)) else: tmp = R * math.sqrt((((lambda1 - lambda2) * (lambda1 - lambda2)) + ((phi1 - phi2) * (phi1 - phi2)))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -3.7e+155) tmp = Float64(R * Float64(Float64(-phi1) * Float64(Float64(Float64(-phi2) / phi1) + 1.0))); else tmp = Float64(R * sqrt(Float64(Float64(Float64(lambda1 - lambda2) * Float64(lambda1 - lambda2)) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (phi1 <= -3.7e+155) tmp = R * (-phi1 * ((-phi2 / phi1) + 1.0)); else tmp = R * sqrt((((lambda1 - lambda2) * (lambda1 - lambda2)) + ((phi1 - phi2) * (phi1 - phi2)))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -3.7e+155], N[(R * N[((-phi1) * N[(N[((-phi2) / phi1), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -3.7 \cdot 10^{+155}:\\
\;\;\;\;R \cdot \left(\left(-\phi_1\right) \cdot \left(\frac{-\phi_2}{\phi_1} + 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \sqrt{\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\
\end{array}
\end{array}
if phi1 < -3.6999999999999998e155Initial program 42.6%
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
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6481.6
Applied rewrites81.6%
if -3.6999999999999998e155 < phi1 Initial program 62.2%
Taylor expanded in phi1 around 0
lower-*.f64N/A
unpow2N/A
sqr-cos-aN/A
lower-+.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lift--.f64N/A
lift--.f6460.8
Applied rewrites60.8%
Taylor expanded in phi2 around 0
pow2N/A
lift--.f64N/A
lift--.f64N/A
lift-*.f6458.9
Applied rewrites58.9%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= R 3.55e+46) (fma (- R) phi1 (* R phi2)) (* R (sqrt (+ (* lambda2 lambda2) (* (- phi1 phi2) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (R <= 3.55e+46) {
tmp = fma(-R, phi1, (R * phi2));
} else {
tmp = R * sqrt(((lambda2 * lambda2) + ((phi1 - phi2) * (phi1 - phi2))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (R <= 3.55e+46) tmp = fma(Float64(-R), phi1, Float64(R * phi2)); else tmp = Float64(R * sqrt(Float64(Float64(lambda2 * lambda2) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[R, 3.55e+46], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[(lambda2 * lambda2), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;R \leq 3.55 \cdot 10^{+46}:\\
\;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \sqrt{\lambda_2 \cdot \lambda_2 + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\
\end{array}
\end{array}
if R < 3.55e46Initial program 51.2%
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-*.f6428.1
Applied rewrites28.1%
Taylor expanded in phi1 around 0
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6428.9
Applied rewrites28.9%
if 3.55e46 < R Initial program 92.1%
Taylor expanded in phi1 around 0
lower-*.f64N/A
unpow2N/A
sqr-cos-aN/A
lower-+.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lift--.f64N/A
lift--.f6491.2
Applied rewrites91.2%
Taylor expanded in lambda1 around 0
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
lower--.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f6478.4
Applied rewrites78.4%
Taylor expanded in phi2 around 0
pow2N/A
lift-*.f6478.1
Applied rewrites78.1%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= (- lambda1 lambda2) -1.7e+177) (* (* phi1 (+ (/ (- R) phi2) (/ R phi1))) phi2) (fma (- R) phi1 (* R phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if ((lambda1 - lambda2) <= -1.7e+177) {
tmp = (phi1 * ((-R / phi2) + (R / phi1))) * phi2;
} else {
tmp = fma(-R, phi1, (R * phi2));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (Float64(lambda1 - lambda2) <= -1.7e+177) tmp = Float64(Float64(phi1 * Float64(Float64(Float64(-R) / phi2) + Float64(R / phi1))) * phi2); else tmp = fma(Float64(-R), phi1, Float64(R * phi2)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -1.7e+177], N[(N[(phi1 * N[(N[((-R) / phi2), $MachinePrecision] + N[(R / phi1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * phi2), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -1.7 \cdot 10^{+177}:\\
\;\;\;\;\left(\phi_1 \cdot \left(\frac{-R}{\phi_2} + \frac{R}{\phi_1}\right)\right) \cdot \phi_2\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
\end{array}
\end{array}
if (-.f64 lambda1 lambda2) < -1.6999999999999999e177Initial program 46.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-*.f6419.8
Applied rewrites19.8%
Taylor expanded in phi1 around inf
lower-*.f64N/A
lower-+.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6422.9
Applied rewrites22.9%
if -1.6999999999999999e177 < (-.f64 lambda1 lambda2) Initial program 63.2%
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-*.f6431.8
Applied rewrites31.8%
Taylor expanded in phi1 around 0
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6432.5
Applied rewrites32.5%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= (- lambda1 lambda2) -1e+177) (* (fma R (/ phi2 phi1) (- R)) phi1) (fma (- R) phi1 (* R phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if ((lambda1 - lambda2) <= -1e+177) {
tmp = fma(R, (phi2 / phi1), -R) * phi1;
} else {
tmp = fma(-R, phi1, (R * phi2));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (Float64(lambda1 - lambda2) <= -1e+177) tmp = Float64(fma(R, Float64(phi2 / phi1), Float64(-R)) * phi1); else tmp = fma(Float64(-R), phi1, Float64(R * phi2)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -1e+177], N[(N[(R * N[(phi2 / phi1), $MachinePrecision] + (-R)), $MachinePrecision] * phi1), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -1 \cdot 10^{+177}:\\
\;\;\;\;\mathsf{fma}\left(R, \frac{\phi_2}{\phi_1}, -R\right) \cdot \phi_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
\end{array}
\end{array}
if (-.f64 lambda1 lambda2) < -1e177Initial program 45.9%
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-*.f6419.8
Applied rewrites19.8%
Taylor expanded in R around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-+.f64N/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6417.6
Applied rewrites17.6%
Taylor expanded in phi1 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6419.3
Applied rewrites19.3%
if -1e177 < (-.f64 lambda1 lambda2) Initial program 63.2%
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-*.f6431.8
Applied rewrites31.8%
Taylor expanded in phi1 around 0
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6432.5
Applied rewrites32.5%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (fma (- R) phi1 (* R phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return fma(-R, phi1, (R * phi2));
}
function code(R, lambda1, lambda2, phi1, phi2) return fma(Float64(-R), phi1, Float64(R * phi2)) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)
\end{array}
Initial program 59.9%
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-*.f6429.5
Applied rewrites29.5%
Taylor expanded in phi1 around 0
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6429.7
Applied rewrites29.7%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 2e+34) (* R (- phi1)) (* R phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 2e+34) {
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 <= 2d+34) 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 <= 2e+34) {
tmp = R * -phi1;
} else {
tmp = R * phi2;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi2 <= 2e+34: tmp = R * -phi1 else: tmp = R * phi2 return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 2e+34) 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 <= 2e+34) tmp = R * -phi1; else tmp = R * phi2; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 2e+34], N[(R * (-phi1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 2 \cdot 10^{+34}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \phi_2\\
\end{array}
\end{array}
if phi2 < 1.99999999999999989e34Initial program 61.8%
Taylor expanded in phi1 around -inf
mul-1-negN/A
lower-neg.f6418.5
Applied rewrites18.5%
if 1.99999999999999989e34 < phi2 Initial program 53.2%
Taylor expanded in phi2 around inf
Applied rewrites63.2%
(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 59.9%
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 59.9%
Taylor expanded in phi1 around inf
Applied rewrites17.4%
herbie shell --seed 2025117
(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))))))