
(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}
Herbie found 11 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}
(FPCore (p r q) :precision binary64 (* 0.5 (+ (+ (fabs p) (fabs r)) (hypot (- r p) (+ q q)))))
double code(double p, double r, double q) {
return 0.5 * ((fabs(p) + fabs(r)) + hypot((r - p), (q + q)));
}
public static double code(double p, double r, double q) {
return 0.5 * ((Math.abs(p) + Math.abs(r)) + Math.hypot((r - p), (q + q)));
}
def code(p, r, q): return 0.5 * ((math.fabs(p) + math.fabs(r)) + math.hypot((r - p), (q + q)))
function code(p, r, q) return Float64(0.5 * Float64(Float64(abs(p) + abs(r)) + hypot(Float64(r - p), Float64(q + q)))) end
function tmp = code(p, r, q) tmp = 0.5 * ((abs(p) + abs(r)) + hypot((r - p), (q + q))); end
code[p_, r_, q_] := N[(0.5 * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(r - p), $MachinePrecision] ^ 2 + N[(q + q), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \mathsf{hypot}\left(r - p, q + q\right)\right)
\end{array}
Initial program 44.7%
Applied rewrites99.9%
Applied rewrites99.9%
Applied rewrites99.9%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (+ (fabs p) (fabs r))))
(if (<= q 7.5e+96)
(fma -0.5 p (* 0.5 (+ r t_0)))
(* 0.5 (+ t_0 (hypot r (+ q q)))))))
double code(double p, double r, double q) {
double t_0 = fabs(p) + fabs(r);
double tmp;
if (q <= 7.5e+96) {
tmp = fma(-0.5, p, (0.5 * (r + t_0)));
} else {
tmp = 0.5 * (t_0 + hypot(r, (q + q)));
}
return tmp;
}
function code(p, r, q) t_0 = Float64(abs(p) + abs(r)) tmp = 0.0 if (q <= 7.5e+96) tmp = fma(-0.5, p, Float64(0.5 * Float64(r + t_0))); else tmp = Float64(0.5 * Float64(t_0 + hypot(r, Float64(q + q)))); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[q, 7.5e+96], N[(-0.5 * p + N[(0.5 * N[(r + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(t$95$0 + N[Sqrt[r ^ 2 + N[(q + q), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|p\right| + \left|r\right|\\
\mathbf{if}\;q \leq 7.5 \cdot 10^{+96}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, p, 0.5 \cdot \left(r + t\_0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(t\_0 + \mathsf{hypot}\left(r, q + q\right)\right)\\
\end{array}
\end{array}
if q < 7.4999999999999996e96Initial program 44.7%
Taylor expanded in p around -inf
Applied rewrites30.0%
Taylor expanded in p around 0
Applied rewrites34.9%
if 7.4999999999999996e96 < q Initial program 44.7%
Applied rewrites99.9%
Applied rewrites99.9%
Applied rewrites99.9%
Taylor expanded in p around 0
Applied rewrites72.4%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (+ (fabs p) (fabs r))))
(if (<= q 2.65e+164)
(fma -0.5 p (* 0.5 (+ r t_0)))
(* q (+ 1.0 (* 0.5 (/ t_0 q)))))))
double code(double p, double r, double q) {
double t_0 = fabs(p) + fabs(r);
double tmp;
if (q <= 2.65e+164) {
tmp = fma(-0.5, p, (0.5 * (r + t_0)));
} else {
tmp = q * (1.0 + (0.5 * (t_0 / q)));
}
return tmp;
}
function code(p, r, q) t_0 = Float64(abs(p) + abs(r)) tmp = 0.0 if (q <= 2.65e+164) tmp = fma(-0.5, p, Float64(0.5 * Float64(r + t_0))); else tmp = Float64(q * Float64(1.0 + Float64(0.5 * Float64(t_0 / q)))); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[q, 2.65e+164], N[(-0.5 * p + N[(0.5 * N[(r + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(q * N[(1.0 + N[(0.5 * N[(t$95$0 / q), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|p\right| + \left|r\right|\\
\mathbf{if}\;q \leq 2.65 \cdot 10^{+164}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, p, 0.5 \cdot \left(r + t\_0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;q \cdot \left(1 + 0.5 \cdot \frac{t\_0}{q}\right)\\
\end{array}
\end{array}
if q < 2.6500000000000002e164Initial program 44.7%
Taylor expanded in p around -inf
Applied rewrites30.0%
Taylor expanded in p around 0
Applied rewrites34.9%
if 2.6500000000000002e164 < q Initial program 44.7%
Taylor expanded in q around inf
Applied rewrites26.3%
(FPCore (p r q) :precision binary64 (if (<= q 3.55e+164) (fma -0.5 p (* 0.5 (+ r (+ (fabs p) (fabs r))))) (* (/ 1.0 2.0) (* 2.0 q))))
double code(double p, double r, double q) {
double tmp;
if (q <= 3.55e+164) {
tmp = fma(-0.5, p, (0.5 * (r + (fabs(p) + fabs(r)))));
} else {
tmp = (1.0 / 2.0) * (2.0 * q);
}
return tmp;
}
function code(p, r, q) tmp = 0.0 if (q <= 3.55e+164) tmp = fma(-0.5, p, Float64(0.5 * Float64(r + Float64(abs(p) + abs(r))))); else tmp = Float64(Float64(1.0 / 2.0) * Float64(2.0 * q)); end return tmp end
code[p_, r_, q_] := If[LessEqual[q, 3.55e+164], N[(-0.5 * p + N[(0.5 * N[(r + N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / 2.0), $MachinePrecision] * N[(2.0 * q), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;q \leq 3.55 \cdot 10^{+164}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, p, 0.5 \cdot \left(r + \left(\left|p\right| + \left|r\right|\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(2 \cdot q\right)\\
\end{array}
\end{array}
if q < 3.5500000000000001e164Initial program 44.7%
Taylor expanded in p around -inf
Applied rewrites30.0%
Taylor expanded in p around 0
Applied rewrites34.9%
if 3.5500000000000001e164 < q Initial program 44.7%
Taylor expanded in q around inf
Applied rewrites17.9%
(FPCore (p r q) :precision binary64 (if (<= q 2.65e+164) (* 0.5 (+ (+ (fabs r) r) (fabs p))) (* (/ 1.0 2.0) (* 2.0 q))))
double code(double p, double r, double q) {
double tmp;
if (q <= 2.65e+164) {
tmp = 0.5 * ((fabs(r) + r) + fabs(p));
} else {
tmp = (1.0 / 2.0) * (2.0 * q);
}
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(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: tmp
if (q <= 2.65d+164) then
tmp = 0.5d0 * ((abs(r) + r) + abs(p))
else
tmp = (1.0d0 / 2.0d0) * (2.0d0 * q)
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (q <= 2.65e+164) {
tmp = 0.5 * ((Math.abs(r) + r) + Math.abs(p));
} else {
tmp = (1.0 / 2.0) * (2.0 * q);
}
return tmp;
}
def code(p, r, q): tmp = 0 if q <= 2.65e+164: tmp = 0.5 * ((math.fabs(r) + r) + math.fabs(p)) else: tmp = (1.0 / 2.0) * (2.0 * q) return tmp
function code(p, r, q) tmp = 0.0 if (q <= 2.65e+164) tmp = Float64(0.5 * Float64(Float64(abs(r) + r) + abs(p))); else tmp = Float64(Float64(1.0 / 2.0) * Float64(2.0 * q)); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (q <= 2.65e+164) tmp = 0.5 * ((abs(r) + r) + abs(p)); else tmp = (1.0 / 2.0) * (2.0 * q); end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[q, 2.65e+164], N[(0.5 * N[(N[(N[Abs[r], $MachinePrecision] + r), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / 2.0), $MachinePrecision] * N[(2.0 * q), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;q \leq 2.65 \cdot 10^{+164}:\\
\;\;\;\;0.5 \cdot \left(\left(\left|r\right| + r\right) + \left|p\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(2 \cdot q\right)\\
\end{array}
\end{array}
if q < 2.6500000000000002e164Initial program 44.7%
Taylor expanded in p around -inf
Applied rewrites30.0%
Applied rewrites30.5%
Taylor expanded in p around 0
Applied rewrites24.8%
Applied rewrites25.2%
if 2.6500000000000002e164 < q Initial program 44.7%
Taylor expanded in q around inf
Applied rewrites17.9%
(FPCore (p r q) :precision binary64 (if (<= q 2.65e+164) (* 0.5 (+ r (+ (fabs p) (fabs r)))) (* (/ 1.0 2.0) (* 2.0 q))))
double code(double p, double r, double q) {
double tmp;
if (q <= 2.65e+164) {
tmp = 0.5 * (r + (fabs(p) + fabs(r)));
} else {
tmp = (1.0 / 2.0) * (2.0 * q);
}
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(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: tmp
if (q <= 2.65d+164) then
tmp = 0.5d0 * (r + (abs(p) + abs(r)))
else
tmp = (1.0d0 / 2.0d0) * (2.0d0 * q)
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (q <= 2.65e+164) {
tmp = 0.5 * (r + (Math.abs(p) + Math.abs(r)));
} else {
tmp = (1.0 / 2.0) * (2.0 * q);
}
return tmp;
}
def code(p, r, q): tmp = 0 if q <= 2.65e+164: tmp = 0.5 * (r + (math.fabs(p) + math.fabs(r))) else: tmp = (1.0 / 2.0) * (2.0 * q) return tmp
function code(p, r, q) tmp = 0.0 if (q <= 2.65e+164) tmp = Float64(0.5 * Float64(r + Float64(abs(p) + abs(r)))); else tmp = Float64(Float64(1.0 / 2.0) * Float64(2.0 * q)); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (q <= 2.65e+164) tmp = 0.5 * (r + (abs(p) + abs(r))); else tmp = (1.0 / 2.0) * (2.0 * q); end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[q, 2.65e+164], N[(0.5 * N[(r + N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / 2.0), $MachinePrecision] * N[(2.0 * q), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;q \leq 2.65 \cdot 10^{+164}:\\
\;\;\;\;0.5 \cdot \left(r + \left(\left|p\right| + \left|r\right|\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(2 \cdot q\right)\\
\end{array}
\end{array}
if q < 2.6500000000000002e164Initial program 44.7%
Taylor expanded in p around -inf
Applied rewrites30.0%
Taylor expanded in p around 0
Applied rewrites24.8%
if 2.6500000000000002e164 < q Initial program 44.7%
Taylor expanded in q around inf
Applied rewrites17.9%
(FPCore (p r q) :precision binary64 (if (<= q 6.8e-29) (* 0.5 (+ (fabs p) (fabs r))) (* (/ 1.0 2.0) (* 2.0 q))))
double code(double p, double r, double q) {
double tmp;
if (q <= 6.8e-29) {
tmp = 0.5 * (fabs(p) + fabs(r));
} else {
tmp = (1.0 / 2.0) * (2.0 * q);
}
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(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: tmp
if (q <= 6.8d-29) then
tmp = 0.5d0 * (abs(p) + abs(r))
else
tmp = (1.0d0 / 2.0d0) * (2.0d0 * q)
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (q <= 6.8e-29) {
tmp = 0.5 * (Math.abs(p) + Math.abs(r));
} else {
tmp = (1.0 / 2.0) * (2.0 * q);
}
return tmp;
}
def code(p, r, q): tmp = 0 if q <= 6.8e-29: tmp = 0.5 * (math.fabs(p) + math.fabs(r)) else: tmp = (1.0 / 2.0) * (2.0 * q) return tmp
function code(p, r, q) tmp = 0.0 if (q <= 6.8e-29) tmp = Float64(0.5 * Float64(abs(p) + abs(r))); else tmp = Float64(Float64(1.0 / 2.0) * Float64(2.0 * q)); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (q <= 6.8e-29) tmp = 0.5 * (abs(p) + abs(r)); else tmp = (1.0 / 2.0) * (2.0 * q); end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[q, 6.8e-29], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / 2.0), $MachinePrecision] * N[(2.0 * q), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;q \leq 6.8 \cdot 10^{-29}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + \left|r\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(2 \cdot q\right)\\
\end{array}
\end{array}
if q < 6.79999999999999945e-29Initial program 44.7%
Taylor expanded in p around -inf
Applied rewrites30.0%
Applied rewrites30.5%
Taylor expanded in p around 0
Applied rewrites24.8%
Taylor expanded in r around 0
Applied rewrites14.5%
if 6.79999999999999945e-29 < q Initial program 44.7%
Taylor expanded in q around inf
Applied rewrites17.9%
(FPCore (p r q) :precision binary64 (* 0.5 (+ (fabs p) (fabs r))))
double code(double p, double r, double q) {
return 0.5 * (fabs(p) + fabs(r));
}
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 = 0.5d0 * (abs(p) + abs(r))
end function
public static double code(double p, double r, double q) {
return 0.5 * (Math.abs(p) + Math.abs(r));
}
def code(p, r, q): return 0.5 * (math.fabs(p) + math.fabs(r))
function code(p, r, q) return Float64(0.5 * Float64(abs(p) + abs(r))) end
function tmp = code(p, r, q) tmp = 0.5 * (abs(p) + abs(r)); end
code[p_, r_, q_] := N[(0.5 * N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(\left|p\right| + \left|r\right|\right)
\end{array}
Initial program 44.7%
Taylor expanded in p around -inf
Applied rewrites30.0%
Applied rewrites30.5%
Taylor expanded in p around 0
Applied rewrites24.8%
Taylor expanded in r around 0
Applied rewrites14.5%
(FPCore (p r q) :precision binary64 (if (<= p -2.8e-16) (* -0.5 p) (* 0.5 r)))
double code(double p, double r, double q) {
double tmp;
if (p <= -2.8e-16) {
tmp = -0.5 * p;
} else {
tmp = 0.5 * r;
}
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(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: tmp
if (p <= (-2.8d-16)) then
tmp = (-0.5d0) * p
else
tmp = 0.5d0 * r
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (p <= -2.8e-16) {
tmp = -0.5 * p;
} else {
tmp = 0.5 * r;
}
return tmp;
}
def code(p, r, q): tmp = 0 if p <= -2.8e-16: tmp = -0.5 * p else: tmp = 0.5 * r return tmp
function code(p, r, q) tmp = 0.0 if (p <= -2.8e-16) tmp = Float64(-0.5 * p); else tmp = Float64(0.5 * r); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (p <= -2.8e-16) tmp = -0.5 * p; else tmp = 0.5 * r; end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[p, -2.8e-16], N[(-0.5 * p), $MachinePrecision], N[(0.5 * r), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;p \leq -2.8 \cdot 10^{-16}:\\
\;\;\;\;-0.5 \cdot p\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot r\\
\end{array}
\end{array}
if p < -2.8000000000000001e-16Initial program 44.7%
Taylor expanded in p around -inf
Applied rewrites5.1%
if -2.8000000000000001e-16 < p Initial program 44.7%
Taylor expanded in r around inf
Applied rewrites5.3%
(FPCore (p r q) :precision binary64 (* -0.5 p))
double code(double p, double r, double q) {
return -0.5 * p;
}
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 = (-0.5d0) * p
end function
public static double code(double p, double r, double q) {
return -0.5 * p;
}
def code(p, r, q): return -0.5 * p
function code(p, r, q) return Float64(-0.5 * p) end
function tmp = code(p, r, q) tmp = -0.5 * p; end
code[p_, r_, q_] := N[(-0.5 * p), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot p
\end{array}
Initial program 44.7%
Taylor expanded in p around -inf
Applied rewrites5.1%
(FPCore (p r q) :precision binary64 (- q))
double code(double p, double r, double q) {
return -q;
}
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 = -q
end function
public static double code(double p, double r, double q) {
return -q;
}
def code(p, r, q): return -q
function code(p, r, q) return Float64(-q) end
function tmp = code(p, r, q) tmp = -q; end
code[p_, r_, q_] := (-q)
\begin{array}{l}
\\
-q
\end{array}
Initial program 44.7%
Taylor expanded in q around -inf
Applied rewrites18.1%
Applied rewrites18.1%
herbie shell --seed 2025161
(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)))))))