
(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]
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
Herbie found 12 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]
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r))) (t_1 (fabs (fmax p r))))
(if (<= (fabs q) 7.2e+104)
(* 0.5 (+ (- t_1 (- (fmin p r) (fmax p r))) t_0))
(fma (+ t_1 t_0) 0.5 (fabs q)))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r));
double t_1 = fabs(fmax(p, r));
double tmp;
if (fabs(q) <= 7.2e+104) {
tmp = 0.5 * ((t_1 - (fmin(p, r) - fmax(p, r))) + t_0);
} else {
tmp = fma((t_1 + t_0), 0.5, fabs(q));
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmin(p, r)) t_1 = abs(fmax(p, r)) tmp = 0.0 if (abs(q) <= 7.2e+104) tmp = Float64(0.5 * Float64(Float64(t_1 - Float64(fmin(p, r) - fmax(p, r))) + t_0)); else tmp = fma(Float64(t_1 + t_0), 0.5, abs(q)); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Abs[q], $MachinePrecision], 7.2e+104], N[(0.5 * N[(N[(t$95$1 - N[(N[Min[p, r], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 + t$95$0), $MachinePrecision] * 0.5 + N[Abs[q], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right|\\
t_1 := \left|\mathsf{max}\left(p, r\right)\right|\\
\mathbf{if}\;\left|q\right| \leq 7.2 \cdot 10^{+104}:\\
\;\;\;\;0.5 \cdot \left(\left(t\_1 - \left(\mathsf{min}\left(p, r\right) - \mathsf{max}\left(p, r\right)\right)\right) + t\_0\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_1 + t\_0, 0.5, \left|q\right|\right)\\
\end{array}
if q < 7.20000000000000001e104Initial program 45.9%
Taylor expanded in r around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites30.3%
Taylor expanded in r around 0
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-*.f6435.0
Applied rewrites35.0%
metadata-evalN/A
metadata-evalN/A
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
lower-fma.f64N/A
metadata-evalN/A
lower-fma.f64N/A
lift-+.f64N/A
lift-*.f64N/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f64N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
metadata-eval35.4
Applied rewrites35.4%
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lift-fma.f64N/A
+-commutativeN/A
lift-fma.f64N/A
lift-*.f64N/A
distribute-rgt-outN/A
*-commutativeN/A
distribute-lft-outN/A
lower-*.f64N/A
metadata-evalN/A
lower-+.f64N/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
lower--.f6435.3
Applied rewrites35.3%
if 7.20000000000000001e104 < q Initial program 45.9%
Taylor expanded in q around inf
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6426.6
Applied rewrites26.6%
metadata-evalN/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
*-rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites26.6%
metadata-evalN/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
Applied rewrites29.0%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r))) (t_1 (fabs (fmax p r))))
(if (<= (fabs q) 7.2e+104)
(* 0.5 (+ (- t_1 (- (fmin p r) (fmax p r))) t_0))
(fma (/ (+ t_1 t_0) (fabs q)) (* 0.5 (fabs q)) (fabs q)))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r));
double t_1 = fabs(fmax(p, r));
double tmp;
if (fabs(q) <= 7.2e+104) {
tmp = 0.5 * ((t_1 - (fmin(p, r) - fmax(p, r))) + t_0);
} else {
tmp = fma(((t_1 + t_0) / fabs(q)), (0.5 * fabs(q)), fabs(q));
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmin(p, r)) t_1 = abs(fmax(p, r)) tmp = 0.0 if (abs(q) <= 7.2e+104) tmp = Float64(0.5 * Float64(Float64(t_1 - Float64(fmin(p, r) - fmax(p, r))) + t_0)); else tmp = fma(Float64(Float64(t_1 + t_0) / abs(q)), Float64(0.5 * abs(q)), abs(q)); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Abs[q], $MachinePrecision], 7.2e+104], N[(0.5 * N[(N[(t$95$1 - N[(N[Min[p, r], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$1 + t$95$0), $MachinePrecision] / N[Abs[q], $MachinePrecision]), $MachinePrecision] * N[(0.5 * N[Abs[q], $MachinePrecision]), $MachinePrecision] + N[Abs[q], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right|\\
t_1 := \left|\mathsf{max}\left(p, r\right)\right|\\
\mathbf{if}\;\left|q\right| \leq 7.2 \cdot 10^{+104}:\\
\;\;\;\;0.5 \cdot \left(\left(t\_1 - \left(\mathsf{min}\left(p, r\right) - \mathsf{max}\left(p, r\right)\right)\right) + t\_0\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t\_1 + t\_0}{\left|q\right|}, 0.5 \cdot \left|q\right|, \left|q\right|\right)\\
\end{array}
if q < 7.20000000000000001e104Initial program 45.9%
Taylor expanded in r around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites30.3%
Taylor expanded in r around 0
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-*.f6435.0
Applied rewrites35.0%
metadata-evalN/A
metadata-evalN/A
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
lower-fma.f64N/A
metadata-evalN/A
lower-fma.f64N/A
lift-+.f64N/A
lift-*.f64N/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f64N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
metadata-eval35.4
Applied rewrites35.4%
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lift-fma.f64N/A
+-commutativeN/A
lift-fma.f64N/A
lift-*.f64N/A
distribute-rgt-outN/A
*-commutativeN/A
distribute-lft-outN/A
lower-*.f64N/A
metadata-evalN/A
lower-+.f64N/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
lower--.f6435.3
Applied rewrites35.3%
if 7.20000000000000001e104 < q Initial program 45.9%
Taylor expanded in q around inf
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6426.6
Applied rewrites26.6%
metadata-evalN/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
*-rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites26.6%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r))) (t_1 (fabs (fmax p r))))
(if (<= (fabs q) 7.2e+104)
(* (- t_1 (- (- (fmin p r) t_0) (fmax p r))) 0.5)
(fma (+ t_1 t_0) 0.5 (fabs q)))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r));
double t_1 = fabs(fmax(p, r));
double tmp;
if (fabs(q) <= 7.2e+104) {
tmp = (t_1 - ((fmin(p, r) - t_0) - fmax(p, r))) * 0.5;
} else {
tmp = fma((t_1 + t_0), 0.5, fabs(q));
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmin(p, r)) t_1 = abs(fmax(p, r)) tmp = 0.0 if (abs(q) <= 7.2e+104) tmp = Float64(Float64(t_1 - Float64(Float64(fmin(p, r) - t_0) - fmax(p, r))) * 0.5); else tmp = fma(Float64(t_1 + t_0), 0.5, abs(q)); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Abs[q], $MachinePrecision], 7.2e+104], N[(N[(t$95$1 - N[(N[(N[Min[p, r], $MachinePrecision] - t$95$0), $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(t$95$1 + t$95$0), $MachinePrecision] * 0.5 + N[Abs[q], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right|\\
t_1 := \left|\mathsf{max}\left(p, r\right)\right|\\
\mathbf{if}\;\left|q\right| \leq 7.2 \cdot 10^{+104}:\\
\;\;\;\;\left(t\_1 - \left(\left(\mathsf{min}\left(p, r\right) - t\_0\right) - \mathsf{max}\left(p, r\right)\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_1 + t\_0, 0.5, \left|q\right|\right)\\
\end{array}
if q < 7.20000000000000001e104Initial program 45.9%
Taylor expanded in r around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites30.3%
Taylor expanded in r around 0
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-*.f6435.0
Applied rewrites35.0%
metadata-evalN/A
metadata-evalN/A
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
lower-fma.f64N/A
metadata-evalN/A
lower-fma.f64N/A
lift-+.f64N/A
lift-*.f64N/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f64N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
metadata-eval35.4
Applied rewrites35.4%
Applied rewrites35.1%
if 7.20000000000000001e104 < q Initial program 45.9%
Taylor expanded in q around inf
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6426.6
Applied rewrites26.6%
metadata-evalN/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
*-rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites26.6%
metadata-evalN/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
Applied rewrites29.0%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmax p r))) (t_1 (fabs (fmin p r))))
(if (<= (fabs q) 7.2e+104)
(* (- (fmax p r) (- (- (fmin p r) t_0) t_1)) 0.5)
(fma (+ t_0 t_1) 0.5 (fabs q)))))double code(double p, double r, double q) {
double t_0 = fabs(fmax(p, r));
double t_1 = fabs(fmin(p, r));
double tmp;
if (fabs(q) <= 7.2e+104) {
tmp = (fmax(p, r) - ((fmin(p, r) - t_0) - t_1)) * 0.5;
} else {
tmp = fma((t_0 + t_1), 0.5, fabs(q));
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmax(p, r)) t_1 = abs(fmin(p, r)) tmp = 0.0 if (abs(q) <= 7.2e+104) tmp = Float64(Float64(fmax(p, r) - Float64(Float64(fmin(p, r) - t_0) - t_1)) * 0.5); else tmp = fma(Float64(t_0 + t_1), 0.5, abs(q)); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Abs[q], $MachinePrecision], 7.2e+104], N[(N[(N[Max[p, r], $MachinePrecision] - N[(N[(N[Min[p, r], $MachinePrecision] - t$95$0), $MachinePrecision] - t$95$1), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(t$95$0 + t$95$1), $MachinePrecision] * 0.5 + N[Abs[q], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \left|\mathsf{max}\left(p, r\right)\right|\\
t_1 := \left|\mathsf{min}\left(p, r\right)\right|\\
\mathbf{if}\;\left|q\right| \leq 7.2 \cdot 10^{+104}:\\
\;\;\;\;\left(\mathsf{max}\left(p, r\right) - \left(\left(\mathsf{min}\left(p, r\right) - t\_0\right) - t\_1\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_0 + t\_1, 0.5, \left|q\right|\right)\\
\end{array}
if q < 7.20000000000000001e104Initial program 45.9%
Taylor expanded in r around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites30.3%
Taylor expanded in r around 0
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-*.f6435.0
Applied rewrites35.0%
metadata-evalN/A
metadata-evalN/A
lift-fma.f64N/A
lift-*.f64N/A
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites35.0%
if 7.20000000000000001e104 < q Initial program 45.9%
Taylor expanded in q around inf
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6426.6
Applied rewrites26.6%
metadata-evalN/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
*-rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites26.6%
metadata-evalN/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
Applied rewrites29.0%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r))) (t_1 (fabs (fmax p r))))
(if (<= (fmax p r) -2.25e-192)
(* 0.5 (- (+ t_0 t_1) (fmin p r)))
(if (<= (fmax p r) 4e+101)
(fma (+ t_1 t_0) 0.5 (fabs q))
(* (+ (+ (fmax p r) t_0) t_1) 0.5)))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r));
double t_1 = fabs(fmax(p, r));
double tmp;
if (fmax(p, r) <= -2.25e-192) {
tmp = 0.5 * ((t_0 + t_1) - fmin(p, r));
} else if (fmax(p, r) <= 4e+101) {
tmp = fma((t_1 + t_0), 0.5, fabs(q));
} else {
tmp = ((fmax(p, r) + t_0) + t_1) * 0.5;
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmin(p, r)) t_1 = abs(fmax(p, r)) tmp = 0.0 if (fmax(p, r) <= -2.25e-192) tmp = Float64(0.5 * Float64(Float64(t_0 + t_1) - fmin(p, r))); elseif (fmax(p, r) <= 4e+101) tmp = fma(Float64(t_1 + t_0), 0.5, abs(q)); else tmp = Float64(Float64(Float64(fmax(p, r) + t_0) + t_1) * 0.5); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Max[p, r], $MachinePrecision], -2.25e-192], N[(0.5 * N[(N[(t$95$0 + t$95$1), $MachinePrecision] - N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Max[p, r], $MachinePrecision], 4e+101], N[(N[(t$95$1 + t$95$0), $MachinePrecision] * 0.5 + N[Abs[q], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Max[p, r], $MachinePrecision] + t$95$0), $MachinePrecision] + t$95$1), $MachinePrecision] * 0.5), $MachinePrecision]]]]]
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right|\\
t_1 := \left|\mathsf{max}\left(p, r\right)\right|\\
\mathbf{if}\;\mathsf{max}\left(p, r\right) \leq -2.25 \cdot 10^{-192}:\\
\;\;\;\;0.5 \cdot \left(\left(t\_0 + t\_1\right) - \mathsf{min}\left(p, r\right)\right)\\
\mathbf{elif}\;\mathsf{max}\left(p, r\right) \leq 4 \cdot 10^{+101}:\\
\;\;\;\;\mathsf{fma}\left(t\_1 + t\_0, 0.5, \left|q\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{max}\left(p, r\right) + t\_0\right) + t\_1\right) \cdot 0.5\\
\end{array}
if r < -2.25000000000000012e-192Initial program 45.9%
Taylor expanded in r around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites30.3%
Taylor expanded in r around 0
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-*.f6435.0
Applied rewrites35.0%
metadata-evalN/A
metadata-evalN/A
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
mul-1-negN/A
sub-flip-reverseN/A
associate-+l-N/A
lower--.f64N/A
lower--.f64N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
metadata-eval35.1
Applied rewrites35.1%
Taylor expanded in r around 0
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6424.4
Applied rewrites24.4%
if -2.25000000000000012e-192 < r < 3.9999999999999999e101Initial program 45.9%
Taylor expanded in q around inf
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6426.6
Applied rewrites26.6%
metadata-evalN/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
*-rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites26.6%
metadata-evalN/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
Applied rewrites29.0%
if 3.9999999999999999e101 < r Initial program 45.9%
Taylor expanded in r around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites30.3%
Taylor expanded in r around 0
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-*.f6435.0
Applied rewrites35.0%
Taylor expanded in p around 0
lower-fabs.f6424.5
Applied rewrites24.5%
metadata-eval24.5
metadata-eval24.5
metadata-evalN/A
metadata-evalN/A
Applied rewrites24.5%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r))) (t_1 (fabs (fmax p r))))
(if (<= (fmin p r) -5.8e+44)
(* 0.5 (- (+ t_0 t_1) (fmin p r)))
(fma (+ t_1 t_0) 0.5 (fabs q)))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r));
double t_1 = fabs(fmax(p, r));
double tmp;
if (fmin(p, r) <= -5.8e+44) {
tmp = 0.5 * ((t_0 + t_1) - fmin(p, r));
} else {
tmp = fma((t_1 + t_0), 0.5, fabs(q));
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmin(p, r)) t_1 = abs(fmax(p, r)) tmp = 0.0 if (fmin(p, r) <= -5.8e+44) tmp = Float64(0.5 * Float64(Float64(t_0 + t_1) - fmin(p, r))); else tmp = fma(Float64(t_1 + t_0), 0.5, abs(q)); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Min[p, r], $MachinePrecision], -5.8e+44], N[(0.5 * N[(N[(t$95$0 + t$95$1), $MachinePrecision] - N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 + t$95$0), $MachinePrecision] * 0.5 + N[Abs[q], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right|\\
t_1 := \left|\mathsf{max}\left(p, r\right)\right|\\
\mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -5.8 \cdot 10^{+44}:\\
\;\;\;\;0.5 \cdot \left(\left(t\_0 + t\_1\right) - \mathsf{min}\left(p, r\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_1 + t\_0, 0.5, \left|q\right|\right)\\
\end{array}
if p < -5.8000000000000004e44Initial program 45.9%
Taylor expanded in r around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites30.3%
Taylor expanded in r around 0
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-*.f6435.0
Applied rewrites35.0%
metadata-evalN/A
metadata-evalN/A
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
mul-1-negN/A
sub-flip-reverseN/A
associate-+l-N/A
lower--.f64N/A
lower--.f64N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
metadata-eval35.1
Applied rewrites35.1%
Taylor expanded in r around 0
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6424.4
Applied rewrites24.4%
if -5.8000000000000004e44 < p Initial program 45.9%
Taylor expanded in q around inf
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6426.6
Applied rewrites26.6%
metadata-evalN/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
*-rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites26.6%
metadata-evalN/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
Applied rewrites29.0%
(FPCore (p r q) :precision binary64 (fma (+ (fabs r) (fabs p)) 0.5 (fabs q)))
double code(double p, double r, double q) {
return fma((fabs(r) + fabs(p)), 0.5, fabs(q));
}
function code(p, r, q) return fma(Float64(abs(r) + abs(p)), 0.5, abs(q)) end
code[p_, r_, q_] := N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] * 0.5 + N[Abs[q], $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(\left|r\right| + \left|p\right|, 0.5, \left|q\right|\right)
Initial program 45.9%
Taylor expanded in q around inf
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6426.6
Applied rewrites26.6%
metadata-evalN/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
*-rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites26.6%
metadata-evalN/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
Applied rewrites29.0%
(FPCore (p r q) :precision binary64 (if (<= (fabs q) 2.75e-31) (* 0.5 (+ (fabs p) (fabs r))) (* (fabs q) 1.0)))
double code(double p, double r, double q) {
double tmp;
if (fabs(q) <= 2.75e-31) {
tmp = 0.5 * (fabs(p) + fabs(r));
} else {
tmp = fabs(q) * 1.0;
}
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 (abs(q) <= 2.75d-31) then
tmp = 0.5d0 * (abs(p) + abs(r))
else
tmp = abs(q) * 1.0d0
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (Math.abs(q) <= 2.75e-31) {
tmp = 0.5 * (Math.abs(p) + Math.abs(r));
} else {
tmp = Math.abs(q) * 1.0;
}
return tmp;
}
def code(p, r, q): tmp = 0 if math.fabs(q) <= 2.75e-31: tmp = 0.5 * (math.fabs(p) + math.fabs(r)) else: tmp = math.fabs(q) * 1.0 return tmp
function code(p, r, q) tmp = 0.0 if (abs(q) <= 2.75e-31) tmp = Float64(0.5 * Float64(abs(p) + abs(r))); else tmp = Float64(abs(q) * 1.0); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (abs(q) <= 2.75e-31) tmp = 0.5 * (abs(p) + abs(r)); else tmp = abs(q) * 1.0; end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[N[Abs[q], $MachinePrecision], 2.75e-31], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Abs[q], $MachinePrecision] * 1.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|q\right| \leq 2.75 \cdot 10^{-31}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + \left|r\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\left|q\right| \cdot 1\\
\end{array}
if q < 2.74999999999999979e-31Initial program 45.9%
Taylor expanded in q around inf
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6426.6
Applied rewrites26.6%
Taylor expanded in q around 0
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6414.4
Applied rewrites14.4%
if 2.74999999999999979e-31 < q Initial program 45.9%
Taylor expanded in q around inf
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6426.6
Applied rewrites26.6%
Taylor expanded in q around inf
Applied rewrites18.2%
(FPCore (p r q) :precision binary64 (if (<= (fabs q) 3.5e-175) (* 0.5 (fmax p r)) (* (fabs q) 1.0)))
double code(double p, double r, double q) {
double tmp;
if (fabs(q) <= 3.5e-175) {
tmp = 0.5 * fmax(p, r);
} else {
tmp = fabs(q) * 1.0;
}
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 (abs(q) <= 3.5d-175) then
tmp = 0.5d0 * fmax(p, r)
else
tmp = abs(q) * 1.0d0
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (Math.abs(q) <= 3.5e-175) {
tmp = 0.5 * fmax(p, r);
} else {
tmp = Math.abs(q) * 1.0;
}
return tmp;
}
def code(p, r, q): tmp = 0 if math.fabs(q) <= 3.5e-175: tmp = 0.5 * fmax(p, r) else: tmp = math.fabs(q) * 1.0 return tmp
function code(p, r, q) tmp = 0.0 if (abs(q) <= 3.5e-175) tmp = Float64(0.5 * fmax(p, r)); else tmp = Float64(abs(q) * 1.0); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (abs(q) <= 3.5e-175) tmp = 0.5 * max(p, r); else tmp = abs(q) * 1.0; end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[N[Abs[q], $MachinePrecision], 3.5e-175], N[(0.5 * N[Max[p, r], $MachinePrecision]), $MachinePrecision], N[(N[Abs[q], $MachinePrecision] * 1.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|q\right| \leq 3.5 \cdot 10^{-175}:\\
\;\;\;\;0.5 \cdot \mathsf{max}\left(p, r\right)\\
\mathbf{else}:\\
\;\;\;\;\left|q\right| \cdot 1\\
\end{array}
if q < 3.49999999999999999e-175Initial program 45.9%
Taylor expanded in r around inf
metadata-evalN/A
lower-*.f64N/A
metadata-eval5.2
Applied rewrites5.2%
if 3.49999999999999999e-175 < q Initial program 45.9%
Taylor expanded in q around inf
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6426.6
Applied rewrites26.6%
Taylor expanded in q around inf
Applied rewrites18.2%
(FPCore (p r q) :precision binary64 (if (<= (fmax p r) 1.75e-37) (* -0.5 (fmin p r)) (* 0.5 (fmax p r))))
double code(double p, double r, double q) {
double tmp;
if (fmax(p, r) <= 1.75e-37) {
tmp = -0.5 * fmin(p, r);
} else {
tmp = 0.5 * fmax(p, 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 (fmax(p, r) <= 1.75d-37) then
tmp = (-0.5d0) * fmin(p, r)
else
tmp = 0.5d0 * fmax(p, r)
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (fmax(p, r) <= 1.75e-37) {
tmp = -0.5 * fmin(p, r);
} else {
tmp = 0.5 * fmax(p, r);
}
return tmp;
}
def code(p, r, q): tmp = 0 if fmax(p, r) <= 1.75e-37: tmp = -0.5 * fmin(p, r) else: tmp = 0.5 * fmax(p, r) return tmp
function code(p, r, q) tmp = 0.0 if (fmax(p, r) <= 1.75e-37) tmp = Float64(-0.5 * fmin(p, r)); else tmp = Float64(0.5 * fmax(p, r)); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (max(p, r) <= 1.75e-37) tmp = -0.5 * min(p, r); else tmp = 0.5 * max(p, r); end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[N[Max[p, r], $MachinePrecision], 1.75e-37], N[(-0.5 * N[Min[p, r], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Max[p, r], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\mathsf{max}\left(p, r\right) \leq 1.75 \cdot 10^{-37}:\\
\;\;\;\;-0.5 \cdot \mathsf{min}\left(p, r\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{max}\left(p, r\right)\\
\end{array}
if r < 1.7500000000000001e-37Initial program 45.9%
Taylor expanded in p around -inf
lower-*.f645.3
Applied rewrites5.3%
if 1.7500000000000001e-37 < r Initial program 45.9%
Taylor expanded in r around inf
metadata-evalN/A
lower-*.f64N/A
metadata-eval5.2
Applied rewrites5.2%
(FPCore (p r q) :precision binary64 (* -0.5 (fmin p r)))
double code(double p, double r, double q) {
return -0.5 * fmin(p, 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) * fmin(p, r)
end function
public static double code(double p, double r, double q) {
return -0.5 * fmin(p, r);
}
def code(p, r, q): return -0.5 * fmin(p, r)
function code(p, r, q) return Float64(-0.5 * fmin(p, r)) end
function tmp = code(p, r, q) tmp = -0.5 * min(p, r); end
code[p_, r_, q_] := N[(-0.5 * N[Min[p, r], $MachinePrecision]), $MachinePrecision]
-0.5 \cdot \mathsf{min}\left(p, r\right)
Initial program 45.9%
Taylor expanded in p around -inf
lower-*.f645.3
Applied rewrites5.3%
(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)
-q
Initial program 45.9%
Taylor expanded in q around -inf
lower-*.f6418.2
Applied rewrites18.2%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6418.2
Applied rewrites18.2%
herbie shell --seed 2025178
(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)))))))