
(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 12 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}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi1 -0.0125) (* R (hypot (* (cos (* -0.5 phi1)) (- lambda1 lambda2)) phi1)) (* R (hypot (* (cos (* -0.5 phi2)) (- lambda1 lambda2)) phi2))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -0.0125) {
tmp = R * hypot((cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
} else {
tmp = R * hypot((cos((-0.5 * phi2)) * (lambda1 - lambda2)), phi2);
}
return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -0.0125) {
tmp = R * Math.hypot((Math.cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
} else {
tmp = R * Math.hypot((Math.cos((-0.5 * phi2)) * (lambda1 - lambda2)), phi2);
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi1 <= -0.0125: tmp = R * math.hypot((math.cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1) else: tmp = R * math.hypot((math.cos((-0.5 * phi2)) * (lambda1 - lambda2)), phi2) return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -0.0125) tmp = Float64(R * hypot(Float64(cos(Float64(-0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1)); else tmp = Float64(R * hypot(Float64(cos(Float64(-0.5 * phi2)) * Float64(lambda1 - lambda2)), phi2)); end return tmp end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
tmp = 0.0;
if (phi1 <= -0.0125)
tmp = R * hypot((cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
else
tmp = R * hypot((cos((-0.5 * phi2)) * (lambda1 - lambda2)), phi2);
end
tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -0.0125], N[(R * N[Sqrt[N[(N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[Cos[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -0.0125:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_2\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_2\right)\\
\end{array}
\end{array}
if phi1 < -0.012500000000000001Initial program 55.9%
Taylor expanded in phi2 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6484.2
Applied rewrites84.2%
if -0.012500000000000001 < phi1 Initial program 59.5%
Taylor expanded in phi1 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6476.9
Applied rewrites76.9%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= phi2 1.65e-234)
(* R (hypot (* (cos (* -0.5 phi1)) lambda2) phi1))
(if (<= phi2 3.7e-6)
(*
R
(hypot
(- (fma (* -0.125 (* phi2 phi2)) (- lambda1 lambda2) lambda1) lambda2)
phi2))
(* R (hypot (* (cos (* 0.5 phi2)) lambda2) phi2)))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 1.65e-234) {
tmp = R * hypot((cos((-0.5 * phi1)) * lambda2), phi1);
} else if (phi2 <= 3.7e-6) {
tmp = R * hypot((fma((-0.125 * (phi2 * phi2)), (lambda1 - lambda2), lambda1) - lambda2), phi2);
} else {
tmp = R * hypot((cos((0.5 * phi2)) * lambda2), phi2);
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 1.65e-234) tmp = Float64(R * hypot(Float64(cos(Float64(-0.5 * phi1)) * lambda2), phi1)); elseif (phi2 <= 3.7e-6) tmp = Float64(R * hypot(Float64(fma(Float64(-0.125 * Float64(phi2 * phi2)), Float64(lambda1 - lambda2), lambda1) - lambda2), phi2)); else tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi2)) * lambda2), phi2)); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 1.65e-234], N[(R * N[Sqrt[N[(N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision] * lambda2), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 3.7e-6], N[(R * N[Sqrt[N[(N[(N[(-0.125 * N[(phi2 * phi2), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision] + lambda1), $MachinePrecision] - lambda2), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * lambda2), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 1.65 \cdot 10^{-234}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \lambda_2, \phi_1\right)\\
\mathbf{elif}\;\phi_2 \leq 3.7 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_2 \cdot \phi_2\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_2, \phi_2\right)\\
\end{array}
\end{array}
if phi2 < 1.65000000000000007e-234Initial program 62.0%
Taylor expanded in phi1 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6462.4
Applied rewrites62.4%
Taylor expanded in phi2 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
cos-neg-revN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
cos-neg-revN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-cos.f64N/A
lower-*.f64N/A
lower--.f6480.4
Applied rewrites80.4%
Taylor expanded in lambda1 around 0
Applied rewrites62.1%
if 1.65000000000000007e-234 < phi2 < 3.7000000000000002e-6Initial program 60.3%
Taylor expanded in phi1 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6467.5
Applied rewrites67.5%
Taylor expanded in phi2 around 0
Applied rewrites67.5%
if 3.7000000000000002e-6 < phi2 Initial program 50.7%
Taylor expanded in phi1 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6473.1
Applied rewrites73.1%
Taylor expanded in lambda1 around 0
Applied rewrites60.0%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= phi2 -6.6e-254)
(* (- phi1) (* (/ R phi2) phi2))
(if (<= phi2 3.7e-6)
(*
R
(hypot
(- (fma (* -0.125 (* phi2 phi2)) (- lambda1 lambda2) lambda1) lambda2)
phi2))
(* R (hypot (* (cos (* 0.5 phi2)) lambda2) phi2)))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= -6.6e-254) {
tmp = -phi1 * ((R / phi2) * phi2);
} else if (phi2 <= 3.7e-6) {
tmp = R * hypot((fma((-0.125 * (phi2 * phi2)), (lambda1 - lambda2), lambda1) - lambda2), phi2);
} else {
tmp = R * hypot((cos((0.5 * phi2)) * lambda2), phi2);
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= -6.6e-254) tmp = Float64(Float64(-phi1) * Float64(Float64(R / phi2) * phi2)); elseif (phi2 <= 3.7e-6) tmp = Float64(R * hypot(Float64(fma(Float64(-0.125 * Float64(phi2 * phi2)), Float64(lambda1 - lambda2), lambda1) - lambda2), phi2)); else tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi2)) * lambda2), phi2)); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, -6.6e-254], N[((-phi1) * N[(N[(R / phi2), $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 3.7e-6], N[(R * N[Sqrt[N[(N[(N[(-0.125 * N[(phi2 * phi2), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision] + lambda1), $MachinePrecision] - lambda2), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * lambda2), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq -6.6 \cdot 10^{-254}:\\
\;\;\;\;\left(-\phi_1\right) \cdot \left(\frac{R}{\phi_2} \cdot \phi_2\right)\\
\mathbf{elif}\;\phi_2 \leq 3.7 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_2 \cdot \phi_2\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_2, \phi_2\right)\\
\end{array}
\end{array}
if phi2 < -6.60000000000000033e-254Initial program 59.1%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6419.6
Applied rewrites19.6%
Taylor expanded in phi2 around inf
Applied rewrites18.6%
Taylor expanded in phi1 around inf
Applied rewrites23.5%
if -6.60000000000000033e-254 < phi2 < 3.7000000000000002e-6Initial program 64.2%
Taylor expanded in phi1 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6464.5
Applied rewrites64.5%
Taylor expanded in phi2 around 0
Applied rewrites64.5%
if 3.7000000000000002e-6 < phi2 Initial program 50.7%
Taylor expanded in phi1 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6473.1
Applied rewrites73.1%
Taylor expanded in lambda1 around 0
Applied rewrites60.0%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= phi1 -7.4e+52)
(* (- R) (- phi1 phi2))
(if (<= phi1 9.5e-307)
(*
R
(hypot
(- (fma (* -0.125 (* phi2 phi2)) (- lambda1 lambda2) lambda1) lambda2)
phi2))
(* R (hypot (* (cos (* 0.5 phi2)) lambda1) phi2)))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -7.4e+52) {
tmp = -R * (phi1 - phi2);
} else if (phi1 <= 9.5e-307) {
tmp = R * hypot((fma((-0.125 * (phi2 * phi2)), (lambda1 - lambda2), lambda1) - lambda2), phi2);
} else {
tmp = R * hypot((cos((0.5 * phi2)) * lambda1), phi2);
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -7.4e+52) tmp = Float64(Float64(-R) * Float64(phi1 - phi2)); elseif (phi1 <= 9.5e-307) tmp = Float64(R * hypot(Float64(fma(Float64(-0.125 * Float64(phi2 * phi2)), Float64(lambda1 - lambda2), lambda1) - lambda2), phi2)); else tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi2)) * lambda1), phi2)); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -7.4e+52], N[((-R) * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 9.5e-307], N[(R * N[Sqrt[N[(N[(N[(-0.125 * N[(phi2 * phi2), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision] + lambda1), $MachinePrecision] - lambda2), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * lambda1), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -7.4 \cdot 10^{+52}:\\
\;\;\;\;\left(-R\right) \cdot \left(\phi_1 - \phi_2\right)\\
\mathbf{elif}\;\phi_1 \leq 9.5 \cdot 10^{-307}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_2 \cdot \phi_2\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_1, \phi_2\right)\\
\end{array}
\end{array}
if phi1 < -7.3999999999999999e52Initial program 60.9%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6477.1
Applied rewrites77.1%
Taylor expanded in phi1 around 0
Applied rewrites77.1%
if -7.3999999999999999e52 < phi1 < 9.5e-307Initial program 56.8%
Taylor expanded in phi1 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6484.7
Applied rewrites84.7%
Taylor expanded in phi2 around 0
Applied rewrites62.0%
if 9.5e-307 < phi1 Initial program 58.4%
Taylor expanded in phi1 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6466.8
Applied rewrites66.8%
Taylor expanded in lambda2 around 0
Applied rewrites48.5%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 3.3e+34) (* R (hypot (* (cos (* -0.5 phi1)) (- lambda1 lambda2)) phi1)) (* R (hypot (* (cos (* 0.5 phi2)) lambda2) phi2))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 3.3e+34) {
tmp = R * hypot((cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
} else {
tmp = R * hypot((cos((0.5 * phi2)) * lambda2), phi2);
}
return tmp;
}
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 3.3e+34) {
tmp = R * Math.hypot((Math.cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
} else {
tmp = R * Math.hypot((Math.cos((0.5 * phi2)) * lambda2), phi2);
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi2 <= 3.3e+34: tmp = R * math.hypot((math.cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1) else: tmp = R * math.hypot((math.cos((0.5 * phi2)) * lambda2), phi2) return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 3.3e+34) tmp = Float64(R * hypot(Float64(cos(Float64(-0.5 * phi1)) * Float64(lambda1 - lambda2)), phi1)); else tmp = Float64(R * hypot(Float64(cos(Float64(0.5 * phi2)) * lambda2), phi2)); end return tmp end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
tmp = 0.0;
if (phi2 <= 3.3e+34)
tmp = R * hypot((cos((-0.5 * phi1)) * (lambda1 - lambda2)), phi1);
else
tmp = R * hypot((cos((0.5 * phi2)) * lambda2), phi2);
end
tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 3.3e+34], N[(R * N[Sqrt[N[(N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2 + phi1 ^ 2], $MachinePrecision]), $MachinePrecision], N[(R * N[Sqrt[N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * lambda2), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 3.3 \cdot 10^{+34}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(-0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right), \phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \lambda_2, \phi_2\right)\\
\end{array}
\end{array}
if phi2 < 3.29999999999999988e34Initial program 61.2%
Taylor expanded in phi2 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6484.2
Applied rewrites84.2%
if 3.29999999999999988e34 < phi2 Initial program 50.2%
Taylor expanded in phi1 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6476.7
Applied rewrites76.7%
Taylor expanded in lambda1 around 0
Applied rewrites66.7%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= phi2 -6.6e-254)
(* (- phi1) (* (/ R phi2) phi2))
(if (<= phi2 2.5)
(*
R
(hypot
(- (fma (* -0.125 (* phi2 phi2)) (- lambda1 lambda2) lambda1) lambda2)
phi2))
(* (- R) (- phi1 phi2)))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= -6.6e-254) {
tmp = -phi1 * ((R / phi2) * phi2);
} else if (phi2 <= 2.5) {
tmp = R * hypot((fma((-0.125 * (phi2 * phi2)), (lambda1 - lambda2), lambda1) - lambda2), phi2);
} else {
tmp = -R * (phi1 - phi2);
}
return tmp;
}
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= -6.6e-254) tmp = Float64(Float64(-phi1) * Float64(Float64(R / phi2) * phi2)); elseif (phi2 <= 2.5) tmp = Float64(R * hypot(Float64(fma(Float64(-0.125 * Float64(phi2 * phi2)), Float64(lambda1 - lambda2), lambda1) - lambda2), phi2)); else tmp = Float64(Float64(-R) * Float64(phi1 - phi2)); end return tmp end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, -6.6e-254], N[((-phi1) * N[(N[(R / phi2), $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 2.5], N[(R * N[Sqrt[N[(N[(N[(-0.125 * N[(phi2 * phi2), $MachinePrecision]), $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision] + lambda1), $MachinePrecision] - lambda2), $MachinePrecision] ^ 2 + phi2 ^ 2], $MachinePrecision]), $MachinePrecision], N[((-R) * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq -6.6 \cdot 10^{-254}:\\
\;\;\;\;\left(-\phi_1\right) \cdot \left(\frac{R}{\phi_2} \cdot \phi_2\right)\\
\mathbf{elif}\;\phi_2 \leq 2.5:\\
\;\;\;\;R \cdot \mathsf{hypot}\left(\mathsf{fma}\left(-0.125 \cdot \left(\phi_2 \cdot \phi_2\right), \lambda_1 - \lambda_2, \lambda_1\right) - \lambda_2, \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-R\right) \cdot \left(\phi_1 - \phi_2\right)\\
\end{array}
\end{array}
if phi2 < -6.60000000000000033e-254Initial program 59.1%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6419.6
Applied rewrites19.6%
Taylor expanded in phi2 around inf
Applied rewrites18.6%
Taylor expanded in phi1 around inf
Applied rewrites23.5%
if -6.60000000000000033e-254 < phi2 < 2.5Initial program 63.5%
Taylor expanded in phi1 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6463.9
Applied rewrites63.9%
Taylor expanded in phi2 around 0
Applied rewrites63.9%
if 2.5 < phi2 Initial program 51.4%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6445.3
Applied rewrites45.3%
Taylor expanded in phi1 around 0
Applied rewrites54.8%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= phi2 -6.6e-254)
(* (- phi1) (* (/ R phi2) phi2))
(if (<= phi2 2e-8)
(* R (* (- lambda1) (- 1.0 (/ lambda2 lambda1))))
(* (- R) (- phi1 phi2)))))assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= -6.6e-254) {
tmp = -phi1 * ((R / phi2) * phi2);
} else if (phi2 <= 2e-8) {
tmp = R * (-lambda1 * (1.0 - (lambda2 / lambda1)));
} else {
tmp = -R * (phi1 - phi2);
}
return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: tmp
if (phi2 <= (-6.6d-254)) then
tmp = -phi1 * ((r / phi2) * phi2)
else if (phi2 <= 2d-8) then
tmp = r * (-lambda1 * (1.0d0 - (lambda2 / lambda1)))
else
tmp = -r * (phi1 - phi2)
end if
code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= -6.6e-254) {
tmp = -phi1 * ((R / phi2) * phi2);
} else if (phi2 <= 2e-8) {
tmp = R * (-lambda1 * (1.0 - (lambda2 / lambda1)));
} else {
tmp = -R * (phi1 - phi2);
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi2 <= -6.6e-254: tmp = -phi1 * ((R / phi2) * phi2) elif phi2 <= 2e-8: tmp = R * (-lambda1 * (1.0 - (lambda2 / lambda1))) else: tmp = -R * (phi1 - phi2) return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= -6.6e-254) tmp = Float64(Float64(-phi1) * Float64(Float64(R / phi2) * phi2)); elseif (phi2 <= 2e-8) tmp = Float64(R * Float64(Float64(-lambda1) * Float64(1.0 - Float64(lambda2 / lambda1)))); else tmp = Float64(Float64(-R) * Float64(phi1 - phi2)); end return tmp end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
tmp = 0.0;
if (phi2 <= -6.6e-254)
tmp = -phi1 * ((R / phi2) * phi2);
elseif (phi2 <= 2e-8)
tmp = R * (-lambda1 * (1.0 - (lambda2 / lambda1)));
else
tmp = -R * (phi1 - phi2);
end
tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, -6.6e-254], N[((-phi1) * N[(N[(R / phi2), $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 2e-8], N[(R * N[((-lambda1) * N[(1.0 - N[(lambda2 / lambda1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-R) * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq -6.6 \cdot 10^{-254}:\\
\;\;\;\;\left(-\phi_1\right) \cdot \left(\frac{R}{\phi_2} \cdot \phi_2\right)\\
\mathbf{elif}\;\phi_2 \leq 2 \cdot 10^{-8}:\\
\;\;\;\;R \cdot \left(\left(-\lambda_1\right) \cdot \left(1 - \frac{\lambda_2}{\lambda_1}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-R\right) \cdot \left(\phi_1 - \phi_2\right)\\
\end{array}
\end{array}
if phi2 < -6.60000000000000033e-254Initial program 59.1%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6419.6
Applied rewrites19.6%
Taylor expanded in phi2 around inf
Applied rewrites18.6%
Taylor expanded in phi1 around inf
Applied rewrites23.5%
if -6.60000000000000033e-254 < phi2 < 2e-8Initial program 63.8%
Taylor expanded in phi1 around 0
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
lower-hypot.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower--.f6465.2
Applied rewrites65.2%
Taylor expanded in lambda1 around -inf
Applied rewrites34.6%
Taylor expanded in phi2 around 0
Applied rewrites34.6%
if 2e-8 < phi2 Initial program 51.4%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6445.4
Applied rewrites45.4%
Taylor expanded in phi1 around 0
Applied rewrites54.7%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= R 1e+168) (* (- R) (- phi1 phi2)) (* (- R (* R (/ phi1 phi2))) phi2)))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (R <= 1e+168) {
tmp = -R * (phi1 - phi2);
} else {
tmp = (R - (R * (phi1 / phi2))) * phi2;
}
return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: tmp
if (r <= 1d+168) then
tmp = -r * (phi1 - phi2)
else
tmp = (r - (r * (phi1 / phi2))) * phi2
end if
code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (R <= 1e+168) {
tmp = -R * (phi1 - phi2);
} else {
tmp = (R - (R * (phi1 / phi2))) * phi2;
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if R <= 1e+168: tmp = -R * (phi1 - phi2) else: tmp = (R - (R * (phi1 / phi2))) * phi2 return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (R <= 1e+168) tmp = Float64(Float64(-R) * Float64(phi1 - phi2)); else tmp = Float64(Float64(R - Float64(R * Float64(phi1 / phi2))) * phi2); end return tmp end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
tmp = 0.0;
if (R <= 1e+168)
tmp = -R * (phi1 - phi2);
else
tmp = (R - (R * (phi1 / phi2))) * phi2;
end
tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[R, 1e+168], N[((-R) * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision], N[(N[(R - N[(R * N[(phi1 / phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * phi2), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;R \leq 10^{+168}:\\
\;\;\;\;\left(-R\right) \cdot \left(\phi_1 - \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;\left(R - R \cdot \frac{\phi_1}{\phi_2}\right) \cdot \phi_2\\
\end{array}
\end{array}
if R < 9.9999999999999993e167Initial program 53.8%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6429.3
Applied rewrites29.3%
Taylor expanded in phi1 around 0
Applied rewrites31.7%
if 9.9999999999999993e167 < R Initial program 100.0%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6430.8
Applied rewrites30.8%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 3.7e-201) (* (- phi1) (* (/ R phi2) phi2)) (* (- R) (- phi1 phi2))))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 3.7e-201) {
tmp = -phi1 * ((R / phi2) * phi2);
} else {
tmp = -R * (phi1 - phi2);
}
return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: tmp
if (phi2 <= 3.7d-201) then
tmp = -phi1 * ((r / phi2) * phi2)
else
tmp = -r * (phi1 - phi2)
end if
code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 3.7e-201) {
tmp = -phi1 * ((R / phi2) * phi2);
} else {
tmp = -R * (phi1 - phi2);
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi2 <= 3.7e-201: tmp = -phi1 * ((R / phi2) * phi2) else: tmp = -R * (phi1 - phi2) return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 3.7e-201) tmp = Float64(Float64(-phi1) * Float64(Float64(R / phi2) * phi2)); else tmp = Float64(Float64(-R) * Float64(phi1 - phi2)); end return tmp end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
tmp = 0.0;
if (phi2 <= 3.7e-201)
tmp = -phi1 * ((R / phi2) * phi2);
else
tmp = -R * (phi1 - phi2);
end
tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, 3.7e-201], N[((-phi1) * N[(N[(R / phi2), $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision], N[((-R) * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq 3.7 \cdot 10^{-201}:\\
\;\;\;\;\left(-\phi_1\right) \cdot \left(\frac{R}{\phi_2} \cdot \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-R\right) \cdot \left(\phi_1 - \phi_2\right)\\
\end{array}
\end{array}
if phi2 < 3.6999999999999998e-201Initial program 63.0%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6420.3
Applied rewrites20.3%
Taylor expanded in phi2 around inf
Applied rewrites19.4%
Taylor expanded in phi1 around inf
Applied rewrites22.9%
if 3.6999999999999998e-201 < phi2 Initial program 52.9%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6439.8
Applied rewrites39.8%
Taylor expanded in phi1 around 0
Applied rewrites44.7%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi1 -0.086) (* R (- phi1)) (* R phi2)))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -0.086) {
tmp = R * -phi1;
} else {
tmp = R * phi2;
}
return tmp;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: tmp
if (phi1 <= (-0.086d0)) then
tmp = r * -phi1
else
tmp = r * phi2
end if
code = tmp
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -0.086) {
tmp = R * -phi1;
} else {
tmp = R * phi2;
}
return tmp;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi1 <= -0.086: tmp = R * -phi1 else: tmp = R * phi2 return tmp
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -0.086) tmp = Float64(R * Float64(-phi1)); else tmp = Float64(R * phi2); end return tmp end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
tmp = 0.0;
if (phi1 <= -0.086)
tmp = R * -phi1;
else
tmp = R * phi2;
end
tmp_2 = tmp;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -0.086], N[(R * (-phi1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -0.086:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \phi_2\\
\end{array}
\end{array}
if phi1 < -0.085999999999999993Initial program 55.9%
Taylor expanded in phi1 around -inf
mul-1-negN/A
lower-neg.f6462.1
Applied rewrites62.1%
if -0.085999999999999993 < phi1 Initial program 59.5%
Taylor expanded in phi2 around inf
lower-*.f6419.3
Applied rewrites19.3%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* (- R) (- phi1 phi2)))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return -R * (phi1 - phi2);
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = -r * (phi1 - phi2)
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return -R * (phi1 - phi2);
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): return -R * (phi1 - phi2)
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(Float64(-R) * Float64(phi1 - phi2)) end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
tmp = -R * (phi1 - phi2);
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[((-R) * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
\left(-R\right) \cdot \left(\phi_1 - \phi_2\right)
\end{array}
Initial program 58.5%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6429.1
Applied rewrites29.1%
Taylor expanded in phi1 around 0
Applied rewrites31.3%
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. (FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi2))
assert(R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * phi2;
}
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * phi2
end function
assert R < lambda1 && lambda1 < lambda2 && lambda2 < phi1 && phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * phi2;
}
[R, lambda1, lambda2, phi1, phi2] = sort([R, lambda1, lambda2, phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): return R * phi2
R, lambda1, lambda2, phi1, phi2 = sort([R, lambda1, lambda2, phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * phi2) end
R, lambda1, lambda2, phi1, phi2 = num2cell(sort([R, lambda1, lambda2, phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
tmp = R * phi2;
end
NOTE: R, lambda1, lambda2, phi1, and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi2), $MachinePrecision]
\begin{array}{l}
[R, lambda1, lambda2, phi1, phi2] = \mathsf{sort}([R, lambda1, lambda2, phi1, phi2])\\
\\
R \cdot \phi_2
\end{array}
Initial program 58.5%
Taylor expanded in phi2 around inf
lower-*.f6416.5
Applied rewrites16.5%
herbie shell --seed 2024358
(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))))))