
(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 15 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 64.4%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites96.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (* 0.5 phi1))))
(if (<= phi2 8.6e+48)
(* (hypot phi1 (* t_0 (- lambda1 lambda2))) 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 (phi2 <= 8.6e+48) {
tmp = hypot(phi1, (t_0 * (lambda1 - lambda2))) * 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 (phi2 <= 8.6e+48) {
tmp = Math.hypot(phi1, (t_0 * (lambda1 - lambda2))) * 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 phi2 <= 8.6e+48: tmp = math.hypot(phi1, (t_0 * (lambda1 - lambda2))) * 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 (phi2 <= 8.6e+48) tmp = Float64(hypot(phi1, Float64(t_0 * Float64(lambda1 - lambda2))) * 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 (phi2 <= 8.6e+48) tmp = hypot(phi1, (t_0 * (lambda1 - lambda2))) * 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[phi2, 8.6e+48], N[(N[Sqrt[phi1 ^ 2 + N[(t$95$0 * N[(lambda1 - lambda2), $MachinePrecision]), $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}\;\phi_2 \leq 8.6 \cdot 10^{+48}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, t\_0 \cdot \left(\lambda_1 - \lambda_2\right)\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 phi2 < 8.59999999999999957e48Initial program 66.2%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites97.0%
Taylor expanded in phi1 around inf
lower-*.f6492.4
Applied rewrites92.4%
Taylor expanded in phi1 around inf
Applied rewrites76.3%
if 8.59999999999999957e48 < phi2 Initial program 58.0%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites95.7%
Taylor expanded in phi1 around inf
lower-*.f6486.0
Applied rewrites86.0%
Taylor expanded in lambda1 around 0
mul-1-negN/A
lower-neg.f6484.2
Applied rewrites84.2%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 1.45e+53) (* (hypot phi1 (* (cos (* 0.5 phi1)) (- lambda1 lambda2))) R) (fma (- R) phi1 (* R phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= 1.45e+53) {
tmp = hypot(phi1, (cos((0.5 * phi1)) * (lambda1 - lambda2))) * R;
} else {
tmp = fma(-R, phi1, (R * phi2));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= 1.45e+53) tmp = Float64(hypot(phi1, Float64(cos(Float64(0.5 * phi1)) * 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, 1.45e+53], N[(N[Sqrt[phi1 ^ 2 + N[(N[Cos[N[(0.5 * phi1), $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 1.45 \cdot 10^{+53}:\\
\;\;\;\;\mathsf{hypot}\left(\phi_1, \cos \left(0.5 \cdot \phi_1\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
\end{array}
\end{array}
if phi2 < 1.4500000000000001e53Initial program 66.2%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites97.0%
Taylor expanded in phi1 around inf
lower-*.f6492.4
Applied rewrites92.4%
Taylor expanded in phi1 around inf
Applied rewrites76.3%
if 1.4500000000000001e53 < phi2 Initial program 58.0%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6466.3
Applied rewrites66.3%
Taylor expanded in phi1 around 0
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-*.f6477.9
Applied rewrites77.9%
(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 64.4%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
Applied rewrites96.7%
Taylor expanded in phi1 around inf
lower-*.f6491.0
Applied rewrites91.0%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= lambda1 -5.6e+132)
(- (* R (* lambda1 (cos (* 0.5 phi2)))))
(if (<= lambda1 1.3e+99)
(* R (- phi2 phi1))
(* (* R lambda2) (cos (* 0.5 (+ phi2 phi1)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda1 <= -5.6e+132) {
tmp = -(R * (lambda1 * cos((0.5 * phi2))));
} else if (lambda1 <= 1.3e+99) {
tmp = R * (phi2 - phi1);
} else {
tmp = (R * lambda2) * cos((0.5 * (phi2 + phi1)));
}
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 (lambda1 <= (-5.6d+132)) then
tmp = -(r * (lambda1 * cos((0.5d0 * phi2))))
else if (lambda1 <= 1.3d+99) then
tmp = r * (phi2 - phi1)
else
tmp = (r * lambda2) * cos((0.5d0 * (phi2 + phi1)))
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda1 <= -5.6e+132) {
tmp = -(R * (lambda1 * Math.cos((0.5 * phi2))));
} else if (lambda1 <= 1.3e+99) {
tmp = R * (phi2 - phi1);
} else {
tmp = (R * lambda2) * Math.cos((0.5 * (phi2 + phi1)));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if lambda1 <= -5.6e+132: tmp = -(R * (lambda1 * math.cos((0.5 * phi2)))) elif lambda1 <= 1.3e+99: tmp = R * (phi2 - phi1) else: tmp = (R * lambda2) * math.cos((0.5 * (phi2 + phi1))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (lambda1 <= -5.6e+132) tmp = Float64(-Float64(R * Float64(lambda1 * cos(Float64(0.5 * phi2))))); elseif (lambda1 <= 1.3e+99) tmp = Float64(R * Float64(phi2 - phi1)); else tmp = Float64(Float64(R * lambda2) * cos(Float64(0.5 * Float64(phi2 + phi1)))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (lambda1 <= -5.6e+132) tmp = -(R * (lambda1 * cos((0.5 * phi2)))); elseif (lambda1 <= 1.3e+99) tmp = R * (phi2 - phi1); else tmp = (R * lambda2) * cos((0.5 * (phi2 + phi1))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -5.6e+132], (-N[(R * N[(lambda1 * N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), If[LessEqual[lambda1, 1.3e+99], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(N[(R * lambda2), $MachinePrecision] * N[Cos[N[(0.5 * N[(phi2 + phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -5.6 \cdot 10^{+132}:\\
\;\;\;\;-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)\\
\mathbf{elif}\;\lambda_1 \leq 1.3 \cdot 10^{+99}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(R \cdot \lambda_2\right) \cdot \cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\\
\end{array}
\end{array}
if lambda1 < -5.5999999999999998e132Initial program 36.9%
Taylor expanded in lambda1 around -inf
mul-1-negN/A
lower-neg.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6457.6
Applied rewrites57.6%
Taylor expanded in phi1 around 0
Applied rewrites55.4%
Taylor expanded in phi1 around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6455.3
Applied rewrites55.3%
if -5.5999999999999998e132 < lambda1 < 1.3e99Initial program 71.9%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6439.4
Applied rewrites39.4%
Taylor expanded in phi1 around 0
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-*.f6438.2
Applied rewrites38.2%
Taylor expanded in R around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6438.8
Applied rewrites38.8%
if 1.3e99 < lambda1 Initial program 60.1%
Taylor expanded in lambda2 around inf
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6412.7
Applied rewrites12.7%
Final simplification36.5%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= lambda1 -5.6e+132) (- (* R (* lambda1 (cos (* 0.5 phi2))))) (* R (- phi2 phi1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda1 <= -5.6e+132) {
tmp = -(R * (lambda1 * cos((0.5 * phi2))));
} else {
tmp = R * (phi2 - phi1);
}
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 (lambda1 <= (-5.6d+132)) then
tmp = -(r * (lambda1 * cos((0.5d0 * phi2))))
else
tmp = r * (phi2 - phi1)
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda1 <= -5.6e+132) {
tmp = -(R * (lambda1 * Math.cos((0.5 * phi2))));
} else {
tmp = R * (phi2 - phi1);
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if lambda1 <= -5.6e+132: tmp = -(R * (lambda1 * math.cos((0.5 * phi2)))) else: tmp = R * (phi2 - phi1) return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (lambda1 <= -5.6e+132) tmp = Float64(-Float64(R * Float64(lambda1 * cos(Float64(0.5 * phi2))))); else tmp = Float64(R * Float64(phi2 - phi1)); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (lambda1 <= -5.6e+132) tmp = -(R * (lambda1 * cos((0.5 * phi2)))); else tmp = R * (phi2 - phi1); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -5.6e+132], (-N[(R * N[(lambda1 * N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -5.6 \cdot 10^{+132}:\\
\;\;\;\;-R \cdot \left(\lambda_1 \cdot \cos \left(0.5 \cdot \phi_2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
\end{array}
\end{array}
if lambda1 < -5.5999999999999998e132Initial program 36.9%
Taylor expanded in lambda1 around -inf
mul-1-negN/A
lower-neg.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6457.6
Applied rewrites57.6%
Taylor expanded in phi1 around 0
Applied rewrites55.4%
Taylor expanded in phi1 around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6455.3
Applied rewrites55.3%
if -5.5999999999999998e132 < lambda1 Initial program 69.4%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6435.8
Applied rewrites35.8%
Taylor expanded in phi1 around 0
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-*.f6434.0
Applied rewrites34.0%
Taylor expanded in R around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6434.5
Applied rewrites34.5%
Final simplification37.7%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= (- lambda1 lambda2) -1e+121) (* (* (fma (/ R phi2) -1.0 (/ R phi1)) phi1) phi2) (* R (- phi2 phi1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if ((lambda1 - lambda2) <= -1e+121) {
tmp = (fma((R / phi2), -1.0, (R / phi1)) * phi1) * phi2;
} else {
tmp = R * (phi2 - phi1);
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (Float64(lambda1 - lambda2) <= -1e+121) tmp = Float64(Float64(fma(Float64(R / phi2), -1.0, Float64(R / phi1)) * phi1) * phi2); else tmp = Float64(R * Float64(phi2 - phi1)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -1e+121], N[(N[(N[(N[(R / phi2), $MachinePrecision] * -1.0 + N[(R / phi1), $MachinePrecision]), $MachinePrecision] * phi1), $MachinePrecision] * phi2), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -1 \cdot 10^{+121}:\\
\;\;\;\;\left(\mathsf{fma}\left(\frac{R}{\phi_2}, -1, \frac{R}{\phi_1}\right) \cdot \phi_1\right) \cdot \phi_2\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
\end{array}
\end{array}
if (-.f64 lambda1 lambda2) < -1.00000000000000004e121Initial program 41.6%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6420.2
Applied rewrites20.2%
Taylor expanded in phi1 around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6421.7
Applied rewrites21.7%
if -1.00000000000000004e121 < (-.f64 lambda1 lambda2) Initial program 71.4%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6436.4
Applied rewrites36.4%
Taylor expanded in phi1 around 0
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-*.f6434.9
Applied rewrites34.9%
Taylor expanded in R around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6435.4
Applied rewrites35.4%
Final simplification32.2%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= (- lambda1 lambda2) -1.08e+231)
(* (- phi1) (fma (* phi2 (/ R phi1)) -1.0 R))
(if (<= (- lambda1 lambda2) -2.4e+176)
(* (fma (* phi1 (/ R phi2)) -1.0 R) phi2)
(* R (- phi2 phi1)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if ((lambda1 - lambda2) <= -1.08e+231) {
tmp = -phi1 * fma((phi2 * (R / phi1)), -1.0, R);
} else if ((lambda1 - lambda2) <= -2.4e+176) {
tmp = fma((phi1 * (R / phi2)), -1.0, R) * phi2;
} else {
tmp = R * (phi2 - phi1);
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (Float64(lambda1 - lambda2) <= -1.08e+231) tmp = Float64(Float64(-phi1) * fma(Float64(phi2 * Float64(R / phi1)), -1.0, R)); elseif (Float64(lambda1 - lambda2) <= -2.4e+176) tmp = Float64(fma(Float64(phi1 * Float64(R / phi2)), -1.0, R) * phi2); else tmp = Float64(R * Float64(phi2 - phi1)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -1.08e+231], N[((-phi1) * N[(N[(phi2 * N[(R / phi1), $MachinePrecision]), $MachinePrecision] * -1.0 + R), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -2.4e+176], N[(N[(N[(phi1 * N[(R / phi2), $MachinePrecision]), $MachinePrecision] * -1.0 + R), $MachinePrecision] * phi2), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -1.08 \cdot 10^{+231}:\\
\;\;\;\;\left(-\phi_1\right) \cdot \mathsf{fma}\left(\phi_2 \cdot \frac{R}{\phi_1}, -1, R\right)\\
\mathbf{elif}\;\lambda_1 - \lambda_2 \leq -2.4 \cdot 10^{+176}:\\
\;\;\;\;\mathsf{fma}\left(\phi_1 \cdot \frac{R}{\phi_2}, -1, R\right) \cdot \phi_2\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
\end{array}
\end{array}
if (-.f64 lambda1 lambda2) < -1.08000000000000001e231Initial program 36.8%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6425.2
Applied rewrites25.2%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6428.6
Applied rewrites28.6%
if -1.08000000000000001e231 < (-.f64 lambda1 lambda2) < -2.4000000000000001e176Initial program 52.6%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6431.4
Applied rewrites31.4%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6441.4
Applied rewrites41.4%
if -2.4000000000000001e176 < (-.f64 lambda1 lambda2) Initial program 68.8%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6434.6
Applied rewrites34.6%
Taylor expanded in phi1 around 0
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-*.f6433.2
Applied rewrites33.2%
Taylor expanded in R around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6433.7
Applied rewrites33.7%
Final simplification33.4%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= (- lambda1 lambda2) -7.5e+153) (* (- phi2) (fma R (/ phi1 phi2) (- R))) (* R (- phi2 phi1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if ((lambda1 - lambda2) <= -7.5e+153) {
tmp = -phi2 * fma(R, (phi1 / phi2), -R);
} else {
tmp = R * (phi2 - phi1);
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (Float64(lambda1 - lambda2) <= -7.5e+153) tmp = Float64(Float64(-phi2) * fma(R, Float64(phi1 / phi2), Float64(-R))); else tmp = Float64(R * Float64(phi2 - phi1)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -7.5e+153], N[((-phi2) * N[(R * N[(phi1 / phi2), $MachinePrecision] + (-R)), $MachinePrecision]), $MachinePrecision], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -7.5 \cdot 10^{+153}:\\
\;\;\;\;\left(-\phi_2\right) \cdot \mathsf{fma}\left(R, \frac{\phi_1}{\phi_2}, -R\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
\end{array}
\end{array}
if (-.f64 lambda1 lambda2) < -7.50000000000000065e153Initial program 40.4%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6421.6
Applied rewrites21.6%
Taylor expanded in phi2 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
mul-1-negN/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6421.6
Applied rewrites21.6%
if -7.50000000000000065e153 < (-.f64 lambda1 lambda2) Initial program 70.4%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6435.8
Applied rewrites35.8%
Taylor expanded in phi1 around 0
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-*.f6434.4
Applied rewrites34.4%
Taylor expanded in R around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6434.9
Applied rewrites34.9%
Final simplification32.3%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi1 -1.5e-21) (* R (- phi2 phi1)) (* (fma (* phi1 (/ R phi2)) -1.0 R) phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -1.5e-21) {
tmp = R * (phi2 - phi1);
} else {
tmp = fma((phi1 * (R / phi2)), -1.0, R) * phi2;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -1.5e-21) tmp = Float64(R * Float64(phi2 - phi1)); else tmp = Float64(fma(Float64(phi1 * Float64(R / phi2)), -1.0, R) * phi2); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -1.5e-21], N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision], N[(N[(N[(phi1 * N[(R / phi2), $MachinePrecision]), $MachinePrecision] * -1.0 + R), $MachinePrecision] * phi2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -1.5 \cdot 10^{-21}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\phi_1 \cdot \frac{R}{\phi_2}, -1, R\right) \cdot \phi_2\\
\end{array}
\end{array}
if phi1 < -1.49999999999999996e-21Initial program 55.1%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6463.2
Applied rewrites63.2%
Taylor expanded in phi1 around 0
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-*.f6460.4
Applied rewrites60.4%
Taylor expanded in R around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6463.1
Applied rewrites63.1%
if -1.49999999999999996e-21 < phi1 Initial program 68.1%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6420.7
Applied rewrites20.7%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6424.4
Applied rewrites24.4%
Final simplification35.3%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 8.6e+48) (* (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 (phi2 <= 8.6e+48) {
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 (phi2 <= 8.6e+48) 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[phi2, 8.6e+48], 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}\;\phi_2 \leq 8.6 \cdot 10^{+48}:\\
\;\;\;\;\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 phi2 < 8.59999999999999957e48Initial program 66.2%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6419.4
Applied rewrites19.4%
Taylor expanded in phi1 around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6420.3
Applied rewrites20.3%
if 8.59999999999999957e48 < phi2 Initial program 58.0%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6466.3
Applied rewrites66.3%
Taylor expanded in phi1 around 0
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-*.f6477.9
Applied rewrites77.9%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi2 -4e-46) (* R (- phi1)) (fma (- R) phi1 (* R phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi2 <= -4e-46) {
tmp = R * -phi1;
} else {
tmp = fma(-R, phi1, (R * phi2));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi2 <= -4e-46) tmp = Float64(R * Float64(-phi1)); else tmp = fma(Float64(-R), phi1, Float64(R * phi2)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi2, -4e-46], N[(R * (-phi1)), $MachinePrecision], N[((-R) * phi1 + N[(R * phi2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_2 \leq -4 \cdot 10^{-46}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-R, \phi_1, R \cdot \phi_2\right)\\
\end{array}
\end{array}
if phi2 < -4.00000000000000009e-46Initial program 63.1%
Taylor expanded in phi1 around -inf
mul-1-negN/A
lower-neg.f6417.7
Applied rewrites17.7%
if -4.00000000000000009e-46 < phi2 Initial program 65.0%
Taylor expanded in phi1 around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6437.9
Applied rewrites37.9%
Taylor expanded in phi1 around 0
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-*.f6439.9
Applied rewrites39.9%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi1 -2.3e-112) (* R (- phi1)) (* R phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -2.3e-112) {
tmp = R * -phi1;
} else {
tmp = R * phi2;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: tmp
if (phi1 <= (-2.3d-112)) then
tmp = r * -phi1
else
tmp = r * phi2
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -2.3e-112) {
tmp = R * -phi1;
} else {
tmp = R * phi2;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi1 <= -2.3e-112: tmp = R * -phi1 else: tmp = R * phi2 return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -2.3e-112) tmp = Float64(R * Float64(-phi1)); else tmp = Float64(R * phi2); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (phi1 <= -2.3e-112) tmp = R * -phi1; else tmp = R * phi2; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -2.3e-112], N[(R * (-phi1)), $MachinePrecision], N[(R * phi2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -2.3 \cdot 10^{-112}:\\
\;\;\;\;R \cdot \left(-\phi_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \phi_2\\
\end{array}
\end{array}
if phi1 < -2.29999999999999991e-112Initial program 61.9%
Taylor expanded in phi1 around -inf
mul-1-negN/A
lower-neg.f6450.3
Applied rewrites50.3%
if -2.29999999999999991e-112 < phi1 Initial program 65.9%
Taylor expanded in phi2 around inf
Applied rewrites19.0%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R (- phi2 phi1)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (phi2 - phi1);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * (phi2 - phi1)
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (phi2 - phi1);
}
def code(R, lambda1, lambda2, phi1, phi2): return R * (phi2 - phi1)
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * Float64(phi2 - phi1)) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * (phi2 - phi1); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \left(\phi_2 - \phi_1\right)
\end{array}
Initial program 64.4%
Taylor expanded in phi2 around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6432.6
Applied rewrites32.6%
Taylor expanded in phi1 around 0
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-*.f6431.1
Applied rewrites31.1%
Taylor expanded in R around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6431.9
Applied rewrites31.9%
Final simplification31.9%
(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 64.4%
Taylor expanded in phi2 around inf
Applied rewrites17.5%
herbie shell --seed 2025064
(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))))))