
(FPCore (p r q) :precision binary64 (* (/ 1.0 2.0) (+ (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
return (1.0 / 2.0) * ((fabs(p) + fabs(r)) + sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
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(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) + sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) + Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q): return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) + math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q) return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) + sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0)))))) end
function tmp = code(p, r, q) tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) + sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0))))); end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (p r q) :precision binary64 (* (/ 1.0 2.0) (+ (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
return (1.0 / 2.0) * ((fabs(p) + fabs(r)) + sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
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(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) + sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) + Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q): return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) + math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q) return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) + sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0)))))) end
function tmp = code(p, r, q) tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) + sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0))))); end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
\end{array}
q_m = (fabs.f64 q) NOTE: p, r, and q_m should be sorted in increasing order before calling this function. (FPCore (p r q_m) :precision binary64 (if (<= q_m 5.4e+122) (* (+ (+ (fabs r) (fabs p)) (- r p)) 0.5) (* 0.5 (+ (+ (fabs p) (fabs r)) (+ q_m q_m)))))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 5.4e+122) {
tmp = ((fabs(r) + fabs(p)) + (r - p)) * 0.5;
} else {
tmp = 0.5 * ((fabs(p) + fabs(r)) + (q_m + q_m));
}
return tmp;
}
q_m = private
NOTE: p, r, and q_m 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(p, r, q_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if (q_m <= 5.4d+122) then
tmp = ((abs(r) + abs(p)) + (r - p)) * 0.5d0
else
tmp = 0.5d0 * ((abs(p) + abs(r)) + (q_m + q_m))
end if
code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 5.4e+122) {
tmp = ((Math.abs(r) + Math.abs(p)) + (r - p)) * 0.5;
} else {
tmp = 0.5 * ((Math.abs(p) + Math.abs(r)) + (q_m + q_m));
}
return tmp;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): tmp = 0 if q_m <= 5.4e+122: tmp = ((math.fabs(r) + math.fabs(p)) + (r - p)) * 0.5 else: tmp = 0.5 * ((math.fabs(p) + math.fabs(r)) + (q_m + q_m)) return tmp
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if (q_m <= 5.4e+122) tmp = Float64(Float64(Float64(abs(r) + abs(p)) + Float64(r - p)) * 0.5); else tmp = Float64(0.5 * Float64(Float64(abs(p) + abs(r)) + Float64(q_m + q_m))); end return tmp end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
tmp = 0.0;
if (q_m <= 5.4e+122)
tmp = ((abs(r) + abs(p)) + (r - p)) * 0.5;
else
tmp = 0.5 * ((abs(p) + abs(r)) + (q_m + q_m));
end
tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 5.4e+122], N[(N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] + N[(r - p), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] + N[(q$95$m + q$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;q\_m \leq 5.4 \cdot 10^{+122}:\\
\;\;\;\;\left(\left(\left|r\right| + \left|p\right|\right) + \left(r - p\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \left(q\_m + q\_m\right)\right)\\
\end{array}
\end{array}
if q < 5.3999999999999997e122Initial program 49.5%
Taylor expanded in r around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6431.4
Applied rewrites31.4%
Taylor expanded in p around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
unpow2N/A
rem-sqrt-square-revN/A
fabs-mulN/A
mul-1-negN/A
neg-fabsN/A
rem-sqrt-square-revN/A
unpow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
lower--.f6436.6
Applied rewrites36.6%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
metadata-eval36.6
Applied rewrites36.6%
if 5.3999999999999997e122 < q Initial program 18.4%
Taylor expanded in q around inf
*-commutativeN/A
lower-*.f6484.8
Applied rewrites84.8%
lift-/.f64N/A
metadata-eval84.8
Applied rewrites84.8%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6484.8
Applied rewrites84.8%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(if (<= r 1.52e-274)
(* 0.5 (+ (fabs p) (- p)))
(if (<= r 2.15e+64)
(* 0.5 (+ (+ (fabs p) (fabs r)) (+ q_m q_m)))
(* 0.5 (+ (fabs p) (+ (fabs r) r))))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (r <= 1.52e-274) {
tmp = 0.5 * (fabs(p) + -p);
} else if (r <= 2.15e+64) {
tmp = 0.5 * ((fabs(p) + fabs(r)) + (q_m + q_m));
} else {
tmp = 0.5 * (fabs(p) + (fabs(r) + r));
}
return tmp;
}
q_m = private
NOTE: p, r, and q_m 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(p, r, q_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if (r <= 1.52d-274) then
tmp = 0.5d0 * (abs(p) + -p)
else if (r <= 2.15d+64) then
tmp = 0.5d0 * ((abs(p) + abs(r)) + (q_m + q_m))
else
tmp = 0.5d0 * (abs(p) + (abs(r) + r))
end if
code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
double tmp;
if (r <= 1.52e-274) {
tmp = 0.5 * (Math.abs(p) + -p);
} else if (r <= 2.15e+64) {
tmp = 0.5 * ((Math.abs(p) + Math.abs(r)) + (q_m + q_m));
} else {
tmp = 0.5 * (Math.abs(p) + (Math.abs(r) + r));
}
return tmp;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): tmp = 0 if r <= 1.52e-274: tmp = 0.5 * (math.fabs(p) + -p) elif r <= 2.15e+64: tmp = 0.5 * ((math.fabs(p) + math.fabs(r)) + (q_m + q_m)) else: tmp = 0.5 * (math.fabs(p) + (math.fabs(r) + r)) return tmp
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if (r <= 1.52e-274) tmp = Float64(0.5 * Float64(abs(p) + Float64(-p))); elseif (r <= 2.15e+64) tmp = Float64(0.5 * Float64(Float64(abs(p) + abs(r)) + Float64(q_m + q_m))); else tmp = Float64(0.5 * Float64(abs(p) + Float64(abs(r) + r))); end return tmp end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
tmp = 0.0;
if (r <= 1.52e-274)
tmp = 0.5 * (abs(p) + -p);
elseif (r <= 2.15e+64)
tmp = 0.5 * ((abs(p) + abs(r)) + (q_m + q_m));
else
tmp = 0.5 * (abs(p) + (abs(r) + r));
end
tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[r, 1.52e-274], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + (-p)), $MachinePrecision]), $MachinePrecision], If[LessEqual[r, 2.15e+64], N[(0.5 * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] + N[(q$95$m + q$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] + r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;r \leq 1.52 \cdot 10^{-274}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + \left(-p\right)\right)\\
\mathbf{elif}\;r \leq 2.15 \cdot 10^{+64}:\\
\;\;\;\;0.5 \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \left(q\_m + q\_m\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + \left(\left|r\right| + r\right)\right)\\
\end{array}
\end{array}
if r < 1.51999999999999989e-274Initial program 40.4%
Taylor expanded in r around inf
Applied rewrites8.4%
lift-/.f64N/A
metadata-eval8.4
Applied rewrites8.4%
lift-+.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-fabs.f64N/A
lower-+.f64N/A
lift-fabs.f649.2
Applied rewrites9.2%
Taylor expanded in p around -inf
mul-1-negN/A
lower-neg.f6420.7
Applied rewrites20.7%
if 1.51999999999999989e-274 < r < 2.1499999999999999e64Initial program 67.1%
Taylor expanded in q around inf
*-commutativeN/A
lower-*.f6439.2
Applied rewrites39.2%
lift-/.f64N/A
metadata-eval39.2
Applied rewrites39.2%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6439.2
Applied rewrites39.2%
if 2.1499999999999999e64 < r Initial program 34.7%
Taylor expanded in r around inf
Applied rewrites68.8%
lift-/.f64N/A
metadata-eval68.8
Applied rewrites68.8%
lift-+.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-fabs.f64N/A
lower-+.f64N/A
lift-fabs.f6468.8
Applied rewrites68.8%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(if (<= r 1.52e-274)
(* 0.5 (+ (fabs p) (- p)))
(if (<= r 2.2e+41)
(* 0.5 (+ (fabs p) (* 2.0 q_m)))
(* 0.5 (+ (fabs p) (+ (fabs r) r))))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (r <= 1.52e-274) {
tmp = 0.5 * (fabs(p) + -p);
} else if (r <= 2.2e+41) {
tmp = 0.5 * (fabs(p) + (2.0 * q_m));
} else {
tmp = 0.5 * (fabs(p) + (fabs(r) + r));
}
return tmp;
}
q_m = private
NOTE: p, r, and q_m 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(p, r, q_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if (r <= 1.52d-274) then
tmp = 0.5d0 * (abs(p) + -p)
else if (r <= 2.2d+41) then
tmp = 0.5d0 * (abs(p) + (2.0d0 * q_m))
else
tmp = 0.5d0 * (abs(p) + (abs(r) + r))
end if
code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
double tmp;
if (r <= 1.52e-274) {
tmp = 0.5 * (Math.abs(p) + -p);
} else if (r <= 2.2e+41) {
tmp = 0.5 * (Math.abs(p) + (2.0 * q_m));
} else {
tmp = 0.5 * (Math.abs(p) + (Math.abs(r) + r));
}
return tmp;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): tmp = 0 if r <= 1.52e-274: tmp = 0.5 * (math.fabs(p) + -p) elif r <= 2.2e+41: tmp = 0.5 * (math.fabs(p) + (2.0 * q_m)) else: tmp = 0.5 * (math.fabs(p) + (math.fabs(r) + r)) return tmp
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if (r <= 1.52e-274) tmp = Float64(0.5 * Float64(abs(p) + Float64(-p))); elseif (r <= 2.2e+41) tmp = Float64(0.5 * Float64(abs(p) + Float64(2.0 * q_m))); else tmp = Float64(0.5 * Float64(abs(p) + Float64(abs(r) + r))); end return tmp end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
tmp = 0.0;
if (r <= 1.52e-274)
tmp = 0.5 * (abs(p) + -p);
elseif (r <= 2.2e+41)
tmp = 0.5 * (abs(p) + (2.0 * q_m));
else
tmp = 0.5 * (abs(p) + (abs(r) + r));
end
tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[r, 1.52e-274], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + (-p)), $MachinePrecision]), $MachinePrecision], If[LessEqual[r, 2.2e+41], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + N[(2.0 * q$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] + r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;r \leq 1.52 \cdot 10^{-274}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + \left(-p\right)\right)\\
\mathbf{elif}\;r \leq 2.2 \cdot 10^{+41}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + 2 \cdot q\_m\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + \left(\left|r\right| + r\right)\right)\\
\end{array}
\end{array}
if r < 1.51999999999999989e-274Initial program 40.4%
Taylor expanded in r around inf
Applied rewrites8.4%
lift-/.f64N/A
metadata-eval8.4
Applied rewrites8.4%
lift-+.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-fabs.f64N/A
lower-+.f64N/A
lift-fabs.f649.2
Applied rewrites9.2%
Taylor expanded in p around -inf
mul-1-negN/A
lower-neg.f6420.7
Applied rewrites20.7%
if 1.51999999999999989e-274 < r < 2.1999999999999999e41Initial program 69.2%
Taylor expanded in r around inf
Applied rewrites19.5%
lift-/.f64N/A
metadata-eval19.5
Applied rewrites19.5%
lift-+.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-fabs.f64N/A
lower-+.f64N/A
lift-fabs.f6419.5
Applied rewrites19.5%
Taylor expanded in q around inf
lower-*.f6439.0
Applied rewrites39.0%
if 2.1999999999999999e41 < r Initial program 33.6%
Taylor expanded in r around inf
Applied rewrites66.6%
lift-/.f64N/A
metadata-eval66.6
Applied rewrites66.6%
lift-+.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-fabs.f64N/A
lower-+.f64N/A
lift-fabs.f6466.6
Applied rewrites66.6%
q_m = (fabs.f64 q) NOTE: p, r, and q_m should be sorted in increasing order before calling this function. (FPCore (p r q_m) :precision binary64 (if (<= r 1.52e-274) (* 0.5 (+ (fabs p) (- p))) (if (<= r 2.15e+64) (* 0.5 (+ (fabs p) (* 2.0 q_m))) r)))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (r <= 1.52e-274) {
tmp = 0.5 * (fabs(p) + -p);
} else if (r <= 2.15e+64) {
tmp = 0.5 * (fabs(p) + (2.0 * q_m));
} else {
tmp = r;
}
return tmp;
}
q_m = private
NOTE: p, r, and q_m 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(p, r, q_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if (r <= 1.52d-274) then
tmp = 0.5d0 * (abs(p) + -p)
else if (r <= 2.15d+64) then
tmp = 0.5d0 * (abs(p) + (2.0d0 * q_m))
else
tmp = r
end if
code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
double tmp;
if (r <= 1.52e-274) {
tmp = 0.5 * (Math.abs(p) + -p);
} else if (r <= 2.15e+64) {
tmp = 0.5 * (Math.abs(p) + (2.0 * q_m));
} else {
tmp = r;
}
return tmp;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): tmp = 0 if r <= 1.52e-274: tmp = 0.5 * (math.fabs(p) + -p) elif r <= 2.15e+64: tmp = 0.5 * (math.fabs(p) + (2.0 * q_m)) else: tmp = r return tmp
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if (r <= 1.52e-274) tmp = Float64(0.5 * Float64(abs(p) + Float64(-p))); elseif (r <= 2.15e+64) tmp = Float64(0.5 * Float64(abs(p) + Float64(2.0 * q_m))); else tmp = r; end return tmp end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
tmp = 0.0;
if (r <= 1.52e-274)
tmp = 0.5 * (abs(p) + -p);
elseif (r <= 2.15e+64)
tmp = 0.5 * (abs(p) + (2.0 * q_m));
else
tmp = r;
end
tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[r, 1.52e-274], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + (-p)), $MachinePrecision]), $MachinePrecision], If[LessEqual[r, 2.15e+64], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + N[(2.0 * q$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], r]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;r \leq 1.52 \cdot 10^{-274}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + \left(-p\right)\right)\\
\mathbf{elif}\;r \leq 2.15 \cdot 10^{+64}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + 2 \cdot q\_m\right)\\
\mathbf{else}:\\
\;\;\;\;r\\
\end{array}
\end{array}
if r < 1.51999999999999989e-274Initial program 40.4%
Taylor expanded in r around inf
Applied rewrites8.4%
lift-/.f64N/A
metadata-eval8.4
Applied rewrites8.4%
lift-+.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-fabs.f64N/A
lower-+.f64N/A
lift-fabs.f649.2
Applied rewrites9.2%
Taylor expanded in p around -inf
mul-1-negN/A
lower-neg.f6420.7
Applied rewrites20.7%
if 1.51999999999999989e-274 < r < 2.1499999999999999e64Initial program 67.1%
Taylor expanded in r around inf
Applied rewrites19.3%
lift-/.f64N/A
metadata-eval19.3
Applied rewrites19.3%
lift-+.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-fabs.f64N/A
lower-+.f64N/A
lift-fabs.f6419.3
Applied rewrites19.3%
Taylor expanded in q around inf
lower-*.f6438.0
Applied rewrites38.0%
if 2.1499999999999999e64 < r Initial program 34.7%
Taylor expanded in p around 0
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.2%
Taylor expanded in r around inf
Applied rewrites66.6%
q_m = (fabs.f64 q) NOTE: p, r, and q_m should be sorted in increasing order before calling this function. (FPCore (p r q_m) :precision binary64 (if (<= p -5.8e+67) (* 0.5 (+ (fabs p) (- p))) (if (<= p 8.2e-282) (* (+ (fma q_m 2.0 r) p) 0.5) (* (+ r (+ r p)) 0.5))))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (p <= -5.8e+67) {
tmp = 0.5 * (fabs(p) + -p);
} else if (p <= 8.2e-282) {
tmp = (fma(q_m, 2.0, r) + p) * 0.5;
} else {
tmp = (r + (r + p)) * 0.5;
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if (p <= -5.8e+67) tmp = Float64(0.5 * Float64(abs(p) + Float64(-p))); elseif (p <= 8.2e-282) tmp = Float64(Float64(fma(q_m, 2.0, r) + p) * 0.5); else tmp = Float64(Float64(r + Float64(r + p)) * 0.5); end return tmp end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[p, -5.8e+67], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + (-p)), $MachinePrecision]), $MachinePrecision], If[LessEqual[p, 8.2e-282], N[(N[(N[(q$95$m * 2.0 + r), $MachinePrecision] + p), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(r + N[(r + p), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;p \leq -5.8 \cdot 10^{+67}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + \left(-p\right)\right)\\
\mathbf{elif}\;p \leq 8.2 \cdot 10^{-282}:\\
\;\;\;\;\left(\mathsf{fma}\left(q\_m, 2, r\right) + p\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(r + \left(r + p\right)\right) \cdot 0.5\\
\end{array}
\end{array}
if p < -5.80000000000000047e67Initial program 29.3%
Taylor expanded in r around inf
Applied rewrites20.5%
lift-/.f64N/A
metadata-eval20.5
Applied rewrites20.5%
lift-+.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-fabs.f64N/A
lower-+.f64N/A
lift-fabs.f6420.6
Applied rewrites20.6%
Taylor expanded in p around -inf
mul-1-negN/A
lower-neg.f6478.8
Applied rewrites78.8%
if -5.80000000000000047e67 < p < 8.19999999999999954e-282Initial program 55.2%
Taylor expanded in p around 0
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites38.7%
Taylor expanded in r around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6430.3
Applied rewrites30.3%
if 8.19999999999999954e-282 < p Initial program 44.1%
Taylor expanded in r around inf
Applied rewrites21.8%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites21.3%
q_m = (fabs.f64 q) NOTE: p, r, and q_m should be sorted in increasing order before calling this function. (FPCore (p r q_m) :precision binary64 (if (<= r 1.16e-273) (* 0.5 (+ (fabs p) (- p))) (if (<= r 2.15e+64) q_m r)))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (r <= 1.16e-273) {
tmp = 0.5 * (fabs(p) + -p);
} else if (r <= 2.15e+64) {
tmp = q_m;
} else {
tmp = r;
}
return tmp;
}
q_m = private
NOTE: p, r, and q_m 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(p, r, q_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if (r <= 1.16d-273) then
tmp = 0.5d0 * (abs(p) + -p)
else if (r <= 2.15d+64) then
tmp = q_m
else
tmp = r
end if
code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
double tmp;
if (r <= 1.16e-273) {
tmp = 0.5 * (Math.abs(p) + -p);
} else if (r <= 2.15e+64) {
tmp = q_m;
} else {
tmp = r;
}
return tmp;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): tmp = 0 if r <= 1.16e-273: tmp = 0.5 * (math.fabs(p) + -p) elif r <= 2.15e+64: tmp = q_m else: tmp = r return tmp
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if (r <= 1.16e-273) tmp = Float64(0.5 * Float64(abs(p) + Float64(-p))); elseif (r <= 2.15e+64) tmp = q_m; else tmp = r; end return tmp end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
tmp = 0.0;
if (r <= 1.16e-273)
tmp = 0.5 * (abs(p) + -p);
elseif (r <= 2.15e+64)
tmp = q_m;
else
tmp = r;
end
tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[r, 1.16e-273], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + (-p)), $MachinePrecision]), $MachinePrecision], If[LessEqual[r, 2.15e+64], q$95$m, r]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;r \leq 1.16 \cdot 10^{-273}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + \left(-p\right)\right)\\
\mathbf{elif}\;r \leq 2.15 \cdot 10^{+64}:\\
\;\;\;\;q\_m\\
\mathbf{else}:\\
\;\;\;\;r\\
\end{array}
\end{array}
if r < 1.1599999999999999e-273Initial program 40.4%
Taylor expanded in r around inf
Applied rewrites8.4%
lift-/.f64N/A
metadata-eval8.4
Applied rewrites8.4%
lift-+.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-fabs.f64N/A
lower-+.f64N/A
lift-fabs.f649.2
Applied rewrites9.2%
Taylor expanded in p around -inf
mul-1-negN/A
lower-neg.f6420.7
Applied rewrites20.7%
if 1.1599999999999999e-273 < r < 2.1499999999999999e64Initial program 67.1%
Taylor expanded in q around inf
Applied rewrites30.3%
if 2.1499999999999999e64 < r Initial program 34.7%
Taylor expanded in p around 0
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.2%
Taylor expanded in r around inf
Applied rewrites66.6%
q_m = (fabs.f64 q) NOTE: p, r, and q_m should be sorted in increasing order before calling this function. (FPCore (p r q_m) :precision binary64 (if (<= r 2.15e+64) q_m r))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (r <= 2.15e+64) {
tmp = q_m;
} else {
tmp = r;
}
return tmp;
}
q_m = private
NOTE: p, r, and q_m 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(p, r, q_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if (r <= 2.15d+64) then
tmp = q_m
else
tmp = r
end if
code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
double tmp;
if (r <= 2.15e+64) {
tmp = q_m;
} else {
tmp = r;
}
return tmp;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): tmp = 0 if r <= 2.15e+64: tmp = q_m else: tmp = r return tmp
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if (r <= 2.15e+64) tmp = q_m; else tmp = r; end return tmp end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
tmp = 0.0;
if (r <= 2.15e+64)
tmp = q_m;
else
tmp = r;
end
tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[r, 2.15e+64], q$95$m, r]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;r \leq 2.15 \cdot 10^{+64}:\\
\;\;\;\;q\_m\\
\mathbf{else}:\\
\;\;\;\;r\\
\end{array}
\end{array}
if r < 2.1499999999999999e64Initial program 48.1%
Taylor expanded in q around inf
Applied rewrites21.8%
if 2.1499999999999999e64 < r Initial program 34.7%
Taylor expanded in p around 0
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.2%
Taylor expanded in r around inf
Applied rewrites66.6%
q_m = (fabs.f64 q) NOTE: p, r, and q_m should be sorted in increasing order before calling this function. (FPCore (p r q_m) :precision binary64 q_m)
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
return q_m;
}
q_m = private
NOTE: p, r, and q_m 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(p, r, q_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
code = q_m
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
return q_m;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): return q_m
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) return q_m end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp = code(p, r, q_m)
tmp = q_m;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := q$95$m
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
q\_m
\end{array}
Initial program 45.4%
Taylor expanded in q around inf
Applied rewrites19.0%
herbie shell --seed 2025053
(FPCore (p r q)
:name "1/2(abs(p)+abs(r) + sqrt((p-r)^2 + 4q^2))"
:precision binary64
(* (/ 1.0 2.0) (+ (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))