
(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}
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}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (let* ((t_0 (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))))) (* R (sqrt (+ (* t_0 t_0) (* (- phi1 phi2) (- phi1 phi2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0));
return R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0d0))
code = r * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda1 - lambda2) * Math.cos(((phi1 + phi2) / 2.0));
return R * Math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = (lambda1 - lambda2) * math.cos(((phi1 + phi2) / 2.0)) return R * math.sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0))) return Float64(R * sqrt(Float64(Float64(t_0 * t_0) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = (lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0)); tmp = R * sqrt(((t_0 * t_0) + ((phi1 - phi2) * (phi1 - phi2)))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(R * N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
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}
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(hypot
(- phi2 phi1)
(fma
(- lambda1 lambda2)
(* (sin (* -0.5 phi2)) (sin (* 0.5 phi1)))
(*
(- lambda1 lambda2)
(* (cos (* 0.5 phi2)) (cos (* -0.5 phi1))))))
R))double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return hypot((phi2 - phi1), fma((lambda1 - lambda2), (sin((-0.5 * phi2)) * sin((0.5 * phi1))), ((lambda1 - lambda2) * (cos((0.5 * phi2)) * cos((-0.5 * phi1)))))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2) return Float64(hypot(Float64(phi2 - phi1), fma(Float64(lambda1 - lambda2), Float64(sin(Float64(-0.5 * phi2)) * sin(Float64(0.5 * phi1))), Float64(Float64(lambda1 - lambda2) * Float64(cos(Float64(0.5 * phi2)) * cos(Float64(-0.5 * phi1)))))) * R) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi2 - phi1), $MachinePrecision] ^ 2 + N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
\mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\lambda_1 - \lambda_2, \sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(-0.5 \cdot \phi_1\right)\right)\right)\right) \cdot R
Initial program 59.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.4%
Applied rewrites95.8%
lift--.f64N/A
flip--N/A
lower-unsound-/.f64N/A
lower-unsound--.f64N/A
lower-unsound-*.f64N/A
lower-unsound-*.f64N/A
lower-unsound-+.f6470.8%
Applied rewrites70.8%
Applied rewrites99.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(hypot
(- phi2 phi1)
(fma
(- lambda1 lambda2)
(* (cos (* 0.5 phi2)) (cos (* -0.5 phi1)))
(*
(- lambda1 lambda2)
(* (sin (* -0.5 phi2)) (sin (* 0.5 phi1))))))
R))double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return hypot((phi2 - phi1), fma((lambda1 - lambda2), (cos((0.5 * phi2)) * cos((-0.5 * phi1))), ((lambda1 - lambda2) * (sin((-0.5 * phi2)) * sin((0.5 * phi1)))))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2) return Float64(hypot(Float64(phi2 - phi1), fma(Float64(lambda1 - lambda2), Float64(cos(Float64(0.5 * phi2)) * cos(Float64(-0.5 * phi1))), Float64(Float64(lambda1 - lambda2) * Float64(sin(Float64(-0.5 * phi2)) * sin(Float64(0.5 * phi1)))))) * R) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi2 - phi1), $MachinePrecision] ^ 2 + N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(-0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[Sin[N[(-0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
\mathsf{hypot}\left(\phi_2 - \phi_1, \mathsf{fma}\left(\lambda_1 - \lambda_2, \cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(-0.5 \cdot \phi_1\right), \left(\lambda_1 - \lambda_2\right) \cdot \left(\sin \left(-0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right)\right) \cdot R
Initial program 59.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.4%
Applied rewrites95.8%
lift--.f64N/A
flip--N/A
lower-unsound-/.f64N/A
lower-unsound--.f64N/A
lower-unsound-*.f64N/A
lower-unsound-*.f64N/A
lower-unsound-+.f6470.8%
Applied rewrites70.8%
Applied rewrites99.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (- (fmax phi1 phi2) (fmin phi1 phi2))))
(if (<= (fmin phi1 phi2) -8.6e-7)
(*
(hypot
t_0
(* (cos (* -0.5 (fmin phi1 phi2))) (- lambda1 lambda2)))
R)
(*
(hypot
t_0
(* (cos (* -0.5 (fmax phi1 phi2))) (- lambda1 lambda2)))
R))))double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = fmax(phi1, phi2) - fmin(phi1, phi2);
double tmp;
if (fmin(phi1, phi2) <= -8.6e-7) {
tmp = hypot(t_0, (cos((-0.5 * fmin(phi1, phi2))) * (lambda1 - lambda2))) * R;
} else {
tmp = hypot(t_0, (cos((-0.5 * fmax(phi1, phi2))) * (lambda1 - lambda2))) * R;
}
return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = fmax(phi1, phi2) - fmin(phi1, phi2);
double tmp;
if (fmin(phi1, phi2) <= -8.6e-7) {
tmp = Math.hypot(t_0, (Math.cos((-0.5 * fmin(phi1, phi2))) * (lambda1 - lambda2))) * R;
} else {
tmp = Math.hypot(t_0, (Math.cos((-0.5 * fmax(phi1, phi2))) * (lambda1 - lambda2))) * R;
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = fmax(phi1, phi2) - fmin(phi1, phi2) tmp = 0 if fmin(phi1, phi2) <= -8.6e-7: tmp = math.hypot(t_0, (math.cos((-0.5 * fmin(phi1, phi2))) * (lambda1 - lambda2))) * R else: tmp = math.hypot(t_0, (math.cos((-0.5 * fmax(phi1, phi2))) * (lambda1 - lambda2))) * R return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(fmax(phi1, phi2) - fmin(phi1, phi2)) tmp = 0.0 if (fmin(phi1, phi2) <= -8.6e-7) tmp = Float64(hypot(t_0, Float64(cos(Float64(-0.5 * fmin(phi1, phi2))) * Float64(lambda1 - lambda2))) * R); else tmp = Float64(hypot(t_0, Float64(cos(Float64(-0.5 * fmax(phi1, phi2))) * Float64(lambda1 - lambda2))) * R); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = max(phi1, phi2) - min(phi1, phi2); tmp = 0.0; if (min(phi1, phi2) <= -8.6e-7) tmp = hypot(t_0, (cos((-0.5 * min(phi1, phi2))) * (lambda1 - lambda2))) * R; else tmp = hypot(t_0, (cos((-0.5 * max(phi1, phi2))) * (lambda1 - lambda2))) * R; end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Min[phi1, phi2], $MachinePrecision], -8.6e-7], N[(N[Sqrt[t$95$0 ^ 2 + N[(N[Cos[N[(-0.5 * N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision], N[(N[Sqrt[t$95$0 ^ 2 + N[(N[Cos[N[(-0.5 * N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
t_0 := \mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right)\\
\mathbf{if}\;\mathsf{min}\left(\phi_1, \phi_2\right) \leq -8.6 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{hypot}\left(t\_0, \cos \left(-0.5 \cdot \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(t\_0, \cos \left(-0.5 \cdot \mathsf{max}\left(\phi_1, \phi_2\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\
\end{array}
if phi1 < -8.6000000000000002e-7Initial program 59.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.4%
Applied rewrites95.8%
Taylor expanded in phi1 around inf
lower-*.f6490.3%
Applied rewrites90.3%
if -8.6000000000000002e-7 < phi1 Initial program 59.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.4%
Applied rewrites95.8%
Taylor expanded in phi1 around 0
lower-*.f6489.8%
Applied rewrites89.8%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* (hypot (- phi2 phi1) (* (cos (* (+ phi2 phi1) -0.5)) (- lambda1 lambda2))) R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return hypot((phi2 - phi1), (cos(((phi2 + phi1) * -0.5)) * (lambda1 - lambda2))) * R;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return Math.hypot((phi2 - phi1), (Math.cos(((phi2 + phi1) * -0.5)) * (lambda1 - lambda2))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.hypot((phi2 - phi1), (math.cos(((phi2 + phi1) * -0.5)) * (lambda1 - lambda2))) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(hypot(Float64(phi2 - phi1), Float64(cos(Float64(Float64(phi2 + phi1) * -0.5)) * Float64(lambda1 - lambda2))) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = hypot((phi2 - phi1), (cos(((phi2 + phi1) * -0.5)) * (lambda1 - lambda2))) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(phi2 - phi1), $MachinePrecision] ^ 2 + N[(N[Cos[N[(N[(phi2 + phi1), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
\mathsf{hypot}\left(\phi_2 - \phi_1, \cos \left(\left(\phi_2 + \phi_1\right) \cdot -0.5\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
Initial program 59.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.4%
Applied rewrites95.8%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* (hypot (- (fmax phi1 phi2) (fmin phi1 phi2)) (* (cos (* -0.5 (fmin phi1 phi2))) (- lambda1 lambda2))) R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return hypot((fmax(phi1, phi2) - fmin(phi1, phi2)), (cos((-0.5 * fmin(phi1, phi2))) * (lambda1 - lambda2))) * R;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return Math.hypot((fmax(phi1, phi2) - fmin(phi1, phi2)), (Math.cos((-0.5 * fmin(phi1, phi2))) * (lambda1 - lambda2))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.hypot((fmax(phi1, phi2) - fmin(phi1, phi2)), (math.cos((-0.5 * fmin(phi1, phi2))) * (lambda1 - lambda2))) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(hypot(Float64(fmax(phi1, phi2) - fmin(phi1, phi2)), Float64(cos(Float64(-0.5 * fmin(phi1, phi2))) * Float64(lambda1 - lambda2))) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = hypot((max(phi1, phi2) - min(phi1, phi2)), (cos((-0.5 * min(phi1, phi2))) * (lambda1 - lambda2))) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[Sqrt[N[(N[Max[phi1, phi2], $MachinePrecision] - N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision] ^ 2 + N[(N[Cos[N[(-0.5 * N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(lambda1 - lambda2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * R), $MachinePrecision]
\mathsf{hypot}\left(\mathsf{max}\left(\phi_1, \phi_2\right) - \mathsf{min}\left(\phi_1, \phi_2\right), \cos \left(-0.5 \cdot \mathsf{min}\left(\phi_1, \phi_2\right)\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) \cdot R
Initial program 59.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.4%
Applied rewrites95.8%
Taylor expanded in phi1 around inf
lower-*.f6490.3%
Applied rewrites90.3%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= (fmax phi1 phi2) 3.4e+187)
(*
-1.0
(*
(fmin phi1 phi2)
(+ R (* -1.0 (/ (* R (fmax phi1 phi2)) (fmin phi1 phi2))))))
(*
R
(*
(fmax phi1 phi2)
(+ 1.0 (* -1.0 (/ (fmin phi1 phi2) (fmax phi1 phi2))))))))double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (fmax(phi1, phi2) <= 3.4e+187) {
tmp = -1.0 * (fmin(phi1, phi2) * (R + (-1.0 * ((R * fmax(phi1, phi2)) / fmin(phi1, phi2)))));
} else {
tmp = R * (fmax(phi1, phi2) * (1.0 + (-1.0 * (fmin(phi1, phi2) / fmax(phi1, phi2)))));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: tmp
if (fmax(phi1, phi2) <= 3.4d+187) then
tmp = (-1.0d0) * (fmin(phi1, phi2) * (r + ((-1.0d0) * ((r * fmax(phi1, phi2)) / fmin(phi1, phi2)))))
else
tmp = r * (fmax(phi1, phi2) * (1.0d0 + ((-1.0d0) * (fmin(phi1, phi2) / fmax(phi1, phi2)))))
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (fmax(phi1, phi2) <= 3.4e+187) {
tmp = -1.0 * (fmin(phi1, phi2) * (R + (-1.0 * ((R * fmax(phi1, phi2)) / fmin(phi1, phi2)))));
} else {
tmp = R * (fmax(phi1, phi2) * (1.0 + (-1.0 * (fmin(phi1, phi2) / fmax(phi1, phi2)))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if fmax(phi1, phi2) <= 3.4e+187: tmp = -1.0 * (fmin(phi1, phi2) * (R + (-1.0 * ((R * fmax(phi1, phi2)) / fmin(phi1, phi2))))) else: tmp = R * (fmax(phi1, phi2) * (1.0 + (-1.0 * (fmin(phi1, phi2) / fmax(phi1, phi2))))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (fmax(phi1, phi2) <= 3.4e+187) tmp = Float64(-1.0 * Float64(fmin(phi1, phi2) * Float64(R + Float64(-1.0 * Float64(Float64(R * fmax(phi1, phi2)) / fmin(phi1, phi2)))))); else tmp = Float64(R * Float64(fmax(phi1, phi2) * Float64(1.0 + Float64(-1.0 * Float64(fmin(phi1, phi2) / fmax(phi1, phi2)))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (max(phi1, phi2) <= 3.4e+187) tmp = -1.0 * (min(phi1, phi2) * (R + (-1.0 * ((R * max(phi1, phi2)) / min(phi1, phi2))))); else tmp = R * (max(phi1, phi2) * (1.0 + (-1.0 * (min(phi1, phi2) / max(phi1, phi2))))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[Max[phi1, phi2], $MachinePrecision], 3.4e+187], N[(-1.0 * N[(N[Min[phi1, phi2], $MachinePrecision] * N[(R + N[(-1.0 * N[(N[(R * N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision] / N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(N[Max[phi1, phi2], $MachinePrecision] * N[(1.0 + N[(-1.0 * N[(N[Min[phi1, phi2], $MachinePrecision] / N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\mathsf{max}\left(\phi_1, \phi_2\right) \leq 3.4 \cdot 10^{+187}:\\
\;\;\;\;-1 \cdot \left(\mathsf{min}\left(\phi_1, \phi_2\right) \cdot \left(R + -1 \cdot \frac{R \cdot \mathsf{max}\left(\phi_1, \phi_2\right)}{\mathsf{min}\left(\phi_1, \phi_2\right)}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\mathsf{max}\left(\phi_1, \phi_2\right) \cdot \left(1 + -1 \cdot \frac{\mathsf{min}\left(\phi_1, \phi_2\right)}{\mathsf{max}\left(\phi_1, \phi_2\right)}\right)\right)\\
\end{array}
if phi2 < 3.4e187Initial program 59.4%
Taylor expanded in phi1 around inf
lower-*.f6416.9%
Applied rewrites16.9%
Taylor expanded in phi1 around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6427.8%
Applied rewrites27.8%
if 3.4e187 < phi2 Initial program 59.4%
Taylor expanded in lambda1 around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-+.f6416.5%
Applied rewrites16.5%
Taylor expanded in phi2 around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f6426.1%
Applied rewrites26.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= (fmax phi1 phi2) 6.2e-42)
(* R (* -1.0 (fmin phi1 phi2)))
(*
R
(*
(fmax phi1 phi2)
(+ 1.0 (* -1.0 (/ (fmin phi1 phi2) (fmax phi1 phi2))))))))double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (fmax(phi1, phi2) <= 6.2e-42) {
tmp = R * (-1.0 * fmin(phi1, phi2));
} else {
tmp = R * (fmax(phi1, phi2) * (1.0 + (-1.0 * (fmin(phi1, phi2) / fmax(phi1, phi2)))));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: tmp
if (fmax(phi1, phi2) <= 6.2d-42) then
tmp = r * ((-1.0d0) * fmin(phi1, phi2))
else
tmp = r * (fmax(phi1, phi2) * (1.0d0 + ((-1.0d0) * (fmin(phi1, phi2) / fmax(phi1, phi2)))))
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (fmax(phi1, phi2) <= 6.2e-42) {
tmp = R * (-1.0 * fmin(phi1, phi2));
} else {
tmp = R * (fmax(phi1, phi2) * (1.0 + (-1.0 * (fmin(phi1, phi2) / fmax(phi1, phi2)))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if fmax(phi1, phi2) <= 6.2e-42: tmp = R * (-1.0 * fmin(phi1, phi2)) else: tmp = R * (fmax(phi1, phi2) * (1.0 + (-1.0 * (fmin(phi1, phi2) / fmax(phi1, phi2))))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (fmax(phi1, phi2) <= 6.2e-42) tmp = Float64(R * Float64(-1.0 * fmin(phi1, phi2))); else tmp = Float64(R * Float64(fmax(phi1, phi2) * Float64(1.0 + Float64(-1.0 * Float64(fmin(phi1, phi2) / fmax(phi1, phi2)))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (max(phi1, phi2) <= 6.2e-42) tmp = R * (-1.0 * min(phi1, phi2)); else tmp = R * (max(phi1, phi2) * (1.0 + (-1.0 * (min(phi1, phi2) / max(phi1, phi2))))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[Max[phi1, phi2], $MachinePrecision], 6.2e-42], N[(R * N[(-1.0 * N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(N[Max[phi1, phi2], $MachinePrecision] * N[(1.0 + N[(-1.0 * N[(N[Min[phi1, phi2], $MachinePrecision] / N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\mathsf{max}\left(\phi_1, \phi_2\right) \leq 6.2 \cdot 10^{-42}:\\
\;\;\;\;R \cdot \left(-1 \cdot \mathsf{min}\left(\phi_1, \phi_2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\mathsf{max}\left(\phi_1, \phi_2\right) \cdot \left(1 + -1 \cdot \frac{\mathsf{min}\left(\phi_1, \phi_2\right)}{\mathsf{max}\left(\phi_1, \phi_2\right)}\right)\right)\\
\end{array}
if phi2 < 6.2000000000000005e-42Initial program 59.4%
Taylor expanded in phi1 around -inf
lower-*.f6417.2%
Applied rewrites17.2%
if 6.2000000000000005e-42 < phi2 Initial program 59.4%
Taylor expanded in lambda1 around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-+.f6416.5%
Applied rewrites16.5%
Taylor expanded in phi2 around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f6426.1%
Applied rewrites26.1%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= (fmin phi1 phi2) -1.4e-25) (* R (* -1.0 (fmin phi1 phi2))) (* R (fmax phi1 phi2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (fmin(phi1, phi2) <= -1.4e-25) {
tmp = R * (-1.0 * fmin(phi1, phi2));
} else {
tmp = R * fmax(phi1, phi2);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: tmp
if (fmin(phi1, phi2) <= (-1.4d-25)) then
tmp = r * ((-1.0d0) * fmin(phi1, phi2))
else
tmp = r * fmax(phi1, phi2)
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (fmin(phi1, phi2) <= -1.4e-25) {
tmp = R * (-1.0 * fmin(phi1, phi2));
} else {
tmp = R * fmax(phi1, phi2);
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if fmin(phi1, phi2) <= -1.4e-25: tmp = R * (-1.0 * fmin(phi1, phi2)) else: tmp = R * fmax(phi1, phi2) return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (fmin(phi1, phi2) <= -1.4e-25) tmp = Float64(R * Float64(-1.0 * fmin(phi1, phi2))); else tmp = Float64(R * fmax(phi1, phi2)); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (min(phi1, phi2) <= -1.4e-25) tmp = R * (-1.0 * min(phi1, phi2)); else tmp = R * max(phi1, phi2); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[N[Min[phi1, phi2], $MachinePrecision], -1.4e-25], N[(R * N[(-1.0 * N[Min[phi1, phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\mathsf{min}\left(\phi_1, \phi_2\right) \leq -1.4 \cdot 10^{-25}:\\
\;\;\;\;R \cdot \left(-1 \cdot \mathsf{min}\left(\phi_1, \phi_2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \mathsf{max}\left(\phi_1, \phi_2\right)\\
\end{array}
if phi1 < -1.3999999999999999e-25Initial program 59.4%
Taylor expanded in phi1 around -inf
lower-*.f6417.2%
Applied rewrites17.2%
if -1.3999999999999999e-25 < phi1 Initial program 59.4%
Taylor expanded in phi2 around inf
lower-*.f6416.6%
Applied rewrites16.6%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R (fmax phi1 phi2)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * fmax(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
code = r * fmax(phi1, phi2)
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * fmax(phi1, phi2);
}
def code(R, lambda1, lambda2, phi1, phi2): return R * fmax(phi1, phi2)
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * fmax(phi1, phi2)) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * max(phi1, phi2); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Max[phi1, phi2], $MachinePrecision]), $MachinePrecision]
R \cdot \mathsf{max}\left(\phi_1, \phi_2\right)
Initial program 59.4%
Taylor expanded in phi2 around inf
lower-*.f6416.6%
Applied rewrites16.6%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R phi1))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * phi1;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, lambda1, lambda2, phi1, phi2)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * phi1
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * phi1;
}
def code(R, lambda1, lambda2, phi1, phi2): return R * phi1
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * phi1) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * phi1; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * phi1), $MachinePrecision]
R \cdot \phi_1
Initial program 59.4%
Taylor expanded in phi1 around inf
lower-*.f6416.9%
Applied rewrites16.9%
herbie shell --seed 2025254
(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))))))