
(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 9 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 45.2%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
sub-flipN/A
add-flipN/A
remove-double-negN/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
lift-pow.f64N/A
unpow2N/A
lift--.f64N/A
sub-negate-revN/A
lift--.f64N/A
sub-negate-revN/A
sqr-negN/A
*-commutativeN/A
associate-*l*N/A
distribute-lft-neg-inN/A
unpow2N/A
lift-pow.f64N/A
distribute-rgt-neg-inN/A
Applied rewrites99.9%
lift-/.f64N/A
metadata-eval99.9
Applied rewrites99.9%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6499.9
Applied rewrites99.9%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (+ (fabs p) (fabs r))))
(if (<= p -8e+106)
(* -1.0 (* p (+ 0.5 (* -0.5 (/ (+ r t_0) p)))))
(* 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 (p <= -8e+106) {
tmp = -1.0 * (p * (0.5 + (-0.5 * ((r + t_0) / p))));
} else {
tmp = 0.5 * (t_0 + hypot(r, (q + q)));
}
return tmp;
}
public static double code(double p, double r, double q) {
double t_0 = Math.abs(p) + Math.abs(r);
double tmp;
if (p <= -8e+106) {
tmp = -1.0 * (p * (0.5 + (-0.5 * ((r + t_0) / p))));
} else {
tmp = 0.5 * (t_0 + Math.hypot(r, (q + q)));
}
return tmp;
}
def code(p, r, q): t_0 = math.fabs(p) + math.fabs(r) tmp = 0 if p <= -8e+106: tmp = -1.0 * (p * (0.5 + (-0.5 * ((r + t_0) / p)))) else: tmp = 0.5 * (t_0 + math.hypot(r, (q + q))) return tmp
function code(p, r, q) t_0 = Float64(abs(p) + abs(r)) tmp = 0.0 if (p <= -8e+106) tmp = Float64(-1.0 * Float64(p * Float64(0.5 + Float64(-0.5 * Float64(Float64(r + t_0) / p))))); else tmp = Float64(0.5 * Float64(t_0 + hypot(r, Float64(q + q)))); end return tmp end
function tmp_2 = code(p, r, q) t_0 = abs(p) + abs(r); tmp = 0.0; if (p <= -8e+106) tmp = -1.0 * (p * (0.5 + (-0.5 * ((r + t_0) / p)))); else tmp = 0.5 * (t_0 + hypot(r, (q + q))); end tmp_2 = tmp; end
code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p, -8e+106], N[(-1.0 * N[(p * N[(0.5 + N[(-0.5 * N[(N[(r + t$95$0), $MachinePrecision] / p), $MachinePrecision]), $MachinePrecision]), $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}\;p \leq -8 \cdot 10^{+106}:\\
\;\;\;\;-1 \cdot \left(p \cdot \left(0.5 + -0.5 \cdot \frac{r + t\_0}{p}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(t\_0 + \mathsf{hypot}\left(r, q + q\right)\right)\\
\end{array}
\end{array}
if p < -8.00000000000000073e106Initial program 45.2%
Taylor expanded in p around -inf
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-/.f64N/A
Applied rewrites29.8%
if -8.00000000000000073e106 < p Initial program 45.2%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
sub-flipN/A
add-flipN/A
remove-double-negN/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
lift-pow.f64N/A
unpow2N/A
lift--.f64N/A
sub-negate-revN/A
lift--.f64N/A
sub-negate-revN/A
sqr-negN/A
*-commutativeN/A
associate-*l*N/A
distribute-lft-neg-inN/A
unpow2N/A
lift-pow.f64N/A
distribute-rgt-neg-inN/A
Applied rewrites99.9%
lift-/.f64N/A
metadata-eval99.9
Applied rewrites99.9%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in p around 0
Applied rewrites73.0%
(FPCore (p r q) :precision binary64 (if (<= q 4.1e+43) (* 0.5 (+ (+ (fabs p) (fabs r)) (* r (+ 1.0 (* -1.0 (/ p r)))))) (fma (+ (fabs r) (fabs p)) 0.5 q)))
double code(double p, double r, double q) {
double tmp;
if (q <= 4.1e+43) {
tmp = 0.5 * ((fabs(p) + fabs(r)) + (r * (1.0 + (-1.0 * (p / r)))));
} else {
tmp = fma((fabs(r) + fabs(p)), 0.5, q);
}
return tmp;
}
function code(p, r, q) tmp = 0.0 if (q <= 4.1e+43) tmp = Float64(0.5 * Float64(Float64(abs(p) + abs(r)) + Float64(r * Float64(1.0 + Float64(-1.0 * Float64(p / r)))))); else tmp = fma(Float64(abs(r) + abs(p)), 0.5, q); end return tmp end
code[p_, r_, q_] := If[LessEqual[q, 4.1e+43], N[(0.5 * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] + N[(r * N[(1.0 + N[(-1.0 * N[(p / r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] * 0.5 + q), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;q \leq 4.1 \cdot 10^{+43}:\\
\;\;\;\;0.5 \cdot \left(\left(\left|p\right| + \left|r\right|\right) + r \cdot \left(1 + -1 \cdot \frac{p}{r}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|r\right| + \left|p\right|, 0.5, q\right)\\
\end{array}
\end{array}
if q < 4.1e43Initial program 45.2%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
sub-flipN/A
add-flipN/A
remove-double-negN/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
lift-pow.f64N/A
unpow2N/A
lift--.f64N/A
sub-negate-revN/A
lift--.f64N/A
sub-negate-revN/A
sqr-negN/A
*-commutativeN/A
associate-*l*N/A
distribute-lft-neg-inN/A
unpow2N/A
lift-pow.f64N/A
distribute-rgt-neg-inN/A
Applied rewrites99.9%
lift-/.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Taylor expanded in r around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f6429.9
Applied rewrites29.9%
if 4.1e43 < q Initial program 45.2%
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
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
sum-to-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
metadata-eval29.2
Applied rewrites29.2%
(FPCore (p r q) :precision binary64 (fma (+ (fabs r) (fabs p)) 0.5 q))
double code(double p, double r, double q) {
return fma((fabs(r) + fabs(p)), 0.5, q);
}
function code(p, r, q) return fma(Float64(abs(r) + abs(p)), 0.5, q) end
code[p_, r_, q_] := N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] * 0.5 + q), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left|r\right| + \left|p\right|, 0.5, q\right)
\end{array}
Initial program 45.2%
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
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
sum-to-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
metadata-eval29.2
Applied rewrites29.2%
(FPCore (p r q) :precision binary64 (if (<= q 1.7e-58) (* 0.5 (+ (fabs p) (fabs r))) (* q 1.0)))
double code(double p, double r, double q) {
double tmp;
if (q <= 1.7e-58) {
tmp = 0.5 * (fabs(p) + fabs(r));
} else {
tmp = 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 (q <= 1.7d-58) then
tmp = 0.5d0 * (abs(p) + abs(r))
else
tmp = q * 1.0d0
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (q <= 1.7e-58) {
tmp = 0.5 * (Math.abs(p) + Math.abs(r));
} else {
tmp = q * 1.0;
}
return tmp;
}
def code(p, r, q): tmp = 0 if q <= 1.7e-58: tmp = 0.5 * (math.fabs(p) + math.fabs(r)) else: tmp = q * 1.0 return tmp
function code(p, r, q) tmp = 0.0 if (q <= 1.7e-58) tmp = Float64(0.5 * Float64(abs(p) + abs(r))); else tmp = Float64(q * 1.0); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (q <= 1.7e-58) tmp = 0.5 * (abs(p) + abs(r)); else tmp = q * 1.0; end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[q, 1.7e-58], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(q * 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;q \leq 1.7 \cdot 10^{-58}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + \left|r\right|\right)\\
\mathbf{else}:\\
\;\;\;\;q \cdot 1\\
\end{array}
\end{array}
if q < 1.69999999999999987e-58Initial program 45.2%
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.3
Applied rewrites14.3%
if 1.69999999999999987e-58 < q Initial program 45.2%
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.5%
(FPCore (p r q) :precision binary64 (if (<= q 1.02e-160) (* 0.5 r) (* q 1.0)))
double code(double p, double r, double q) {
double tmp;
if (q <= 1.02e-160) {
tmp = 0.5 * r;
} else {
tmp = 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 (q <= 1.02d-160) then
tmp = 0.5d0 * r
else
tmp = q * 1.0d0
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (q <= 1.02e-160) {
tmp = 0.5 * r;
} else {
tmp = q * 1.0;
}
return tmp;
}
def code(p, r, q): tmp = 0 if q <= 1.02e-160: tmp = 0.5 * r else: tmp = q * 1.0 return tmp
function code(p, r, q) tmp = 0.0 if (q <= 1.02e-160) tmp = Float64(0.5 * r); else tmp = Float64(q * 1.0); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (q <= 1.02e-160) tmp = 0.5 * r; else tmp = q * 1.0; end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[q, 1.02e-160], N[(0.5 * r), $MachinePrecision], N[(q * 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;q \leq 1.02 \cdot 10^{-160}:\\
\;\;\;\;0.5 \cdot r\\
\mathbf{else}:\\
\;\;\;\;q \cdot 1\\
\end{array}
\end{array}
if q < 1.0200000000000001e-160Initial program 45.2%
Taylor expanded in r around inf
metadata-evalN/A
lower-*.f64N/A
metadata-eval5.3
Applied rewrites5.3%
if 1.0200000000000001e-160 < q Initial program 45.2%
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.5%
(FPCore (p r q) :precision binary64 (if (<= p -7e-87) (* -0.5 p) (* 0.5 r)))
double code(double p, double r, double q) {
double tmp;
if (p <= -7e-87) {
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 <= (-7d-87)) 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 <= -7e-87) {
tmp = -0.5 * p;
} else {
tmp = 0.5 * r;
}
return tmp;
}
def code(p, r, q): tmp = 0 if p <= -7e-87: tmp = -0.5 * p else: tmp = 0.5 * r return tmp
function code(p, r, q) tmp = 0.0 if (p <= -7e-87) 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 <= -7e-87) tmp = -0.5 * p; else tmp = 0.5 * r; end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[p, -7e-87], N[(-0.5 * p), $MachinePrecision], N[(0.5 * r), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;p \leq -7 \cdot 10^{-87}:\\
\;\;\;\;-0.5 \cdot p\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot r\\
\end{array}
\end{array}
if p < -7.00000000000000023e-87Initial program 45.2%
Taylor expanded in p around -inf
lower-*.f645.1
Applied rewrites5.1%
if -7.00000000000000023e-87 < p Initial program 45.2%
Taylor expanded in r around inf
metadata-evalN/A
lower-*.f64N/A
metadata-eval5.3
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 45.2%
Taylor expanded in p around -inf
lower-*.f645.1
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 45.2%
Taylor expanded in q around -inf
lower-*.f6418.7
Applied rewrites18.7%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6418.7
Applied rewrites18.7%
herbie shell --seed 2025156
(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)))))))