
(FPCore (p r q) :precision binary64 (* (/ 1.0 2.0) (+ (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
return (1.0 / 2.0) * ((fabs(p) + fabs(r)) + sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) + sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) + Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q): return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) + math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q) return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) + sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0)))))) end
function tmp = code(p, r, q) tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) + sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0))))); end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 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}
NOTE: p, r, and q should be sorted in increasing order before calling this function.
(FPCore (p r q)
:precision binary64
(let* ((t_0
(*
(/ 1.0 2.0)
(+
(+ (fabs p) (fabs r))
(sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0))))))))
(if (<= t_0 2e+148) t_0 (* (+ (+ (fabs r) (fabs p)) (+ (- p) r)) 0.5))))assert(p < r && r < q);
double code(double p, double r, double q) {
double t_0 = (1.0 / 2.0) * ((fabs(p) + fabs(r)) + sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
double tmp;
if (t_0 <= 2e+148) {
tmp = t_0;
} else {
tmp = ((fabs(r) + fabs(p)) + (-p + r)) * 0.5;
}
return tmp;
}
NOTE: p, r, and q should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) + sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
if (t_0 <= 2d+148) then
tmp = t_0
else
tmp = ((abs(r) + abs(p)) + (-p + r)) * 0.5d0
end if
code = tmp
end function
assert p < r && r < q;
public static double code(double p, double r, double q) {
double t_0 = (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)))));
double tmp;
if (t_0 <= 2e+148) {
tmp = t_0;
} else {
tmp = ((Math.abs(r) + Math.abs(p)) + (-p + r)) * 0.5;
}
return tmp;
}
[p, r, q] = sort([p, r, q]) def code(p, r, q): t_0 = (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))))) tmp = 0 if t_0 <= 2e+148: tmp = t_0 else: tmp = ((math.fabs(r) + math.fabs(p)) + (-p + r)) * 0.5 return tmp
p, r, q = sort([p, r, q]) function code(p, r, q) t_0 = 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)))))) tmp = 0.0 if (t_0 <= 2e+148) tmp = t_0; else tmp = Float64(Float64(Float64(abs(r) + abs(p)) + Float64(Float64(-p) + r)) * 0.5); end return tmp end
p, r, q = num2cell(sort([p, r, q])){:}
function tmp_2 = code(p, r, q)
t_0 = (1.0 / 2.0) * ((abs(p) + abs(r)) + sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0)))));
tmp = 0.0;
if (t_0 <= 2e+148)
tmp = t_0;
else
tmp = ((abs(r) + abs(p)) + (-p + r)) * 0.5;
end
tmp_2 = tmp;
end
NOTE: p, r, and q should be sorted in increasing order before calling this function.
code[p_, r_, q_] := Block[{t$95$0 = 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]}, If[LessEqual[t$95$0, 2e+148], t$95$0, N[(N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] + N[((-p) + r), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
[p, r, q] = \mathsf{sort}([p, r, q])\\
\\
\begin{array}{l}
t_0 := \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{+148}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left|r\right| + \left|p\right|\right) + \left(\left(-p\right) + r\right)\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (+.f64 (+.f64 (fabs.f64 p) (fabs.f64 r)) (sqrt.f64 (+.f64 (pow.f64 (-.f64 p r) #s(literal 2 binary64)) (*.f64 #s(literal 4 binary64) (pow.f64 q #s(literal 2 binary64))))))) < 2.0000000000000001e148Initial program 96.7%
if 2.0000000000000001e148 < (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (+.f64 (+.f64 (fabs.f64 p) (fabs.f64 r)) (sqrt.f64 (+.f64 (pow.f64 (-.f64 p r) #s(literal 2 binary64)) (*.f64 #s(literal 4 binary64) (pow.f64 q #s(literal 2 binary64))))))) Initial program 8.2%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6422.7
Applied rewrites22.7%
Taylor expanded in p around 0
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
lower-fma.f6430.2
Applied rewrites30.2%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
metadata-eval30.2
Applied rewrites30.2%
lift-fma.f64N/A
mul-1-negN/A
lower-+.f64N/A
lift-neg.f6430.2
Applied rewrites30.2%
NOTE: p, r, and q should be sorted in increasing order before calling this function.
(FPCore (p r q)
:precision binary64
(let* ((t_0 (+ (fabs r) (fabs p))))
(if (<= p -2.35e+42)
(* (+ (- p) t_0) 0.5)
(if (<= p 5.8e-208) (fma t_0 0.5 q) (fma q (/ q r) r)))))assert(p < r && r < q);
double code(double p, double r, double q) {
double t_0 = fabs(r) + fabs(p);
double tmp;
if (p <= -2.35e+42) {
tmp = (-p + t_0) * 0.5;
} else if (p <= 5.8e-208) {
tmp = fma(t_0, 0.5, q);
} else {
tmp = fma(q, (q / r), r);
}
return tmp;
}
p, r, q = sort([p, r, q]) function code(p, r, q) t_0 = Float64(abs(r) + abs(p)) tmp = 0.0 if (p <= -2.35e+42) tmp = Float64(Float64(Float64(-p) + t_0) * 0.5); elseif (p <= 5.8e-208) tmp = fma(t_0, 0.5, q); else tmp = fma(q, Float64(q / r), r); end return tmp end
NOTE: p, r, and q should be sorted in increasing order before calling this function.
code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p, -2.35e+42], N[(N[((-p) + t$95$0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[p, 5.8e-208], N[(t$95$0 * 0.5 + q), $MachinePrecision], N[(q * N[(q / r), $MachinePrecision] + r), $MachinePrecision]]]]
\begin{array}{l}
[p, r, q] = \mathsf{sort}([p, r, q])\\
\\
\begin{array}{l}
t_0 := \left|r\right| + \left|p\right|\\
\mathbf{if}\;p \leq -2.35 \cdot 10^{+42}:\\
\;\;\;\;\left(\left(-p\right) + t\_0\right) \cdot 0.5\\
\mathbf{elif}\;p \leq 5.8 \cdot 10^{-208}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, 0.5, q\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(q, \frac{q}{r}, r\right)\\
\end{array}
\end{array}
if p < -2.34999999999999993e42Initial program 29.9%
Taylor expanded in p around -inf
mul-1-negN/A
lower-neg.f6472.9
Applied rewrites72.9%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites72.9%
if -2.34999999999999993e42 < p < 5.7999999999999999e-208Initial program 57.9%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6419.0
Applied rewrites19.0%
Taylor expanded in q around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites34.4%
Taylor expanded in q around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
lift-+.f6436.2
Applied rewrites36.2%
if 5.7999999999999999e-208 < p Initial program 39.0%
Taylor expanded in p around 0
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites25.4%
Taylor expanded in q around 0
metadata-evalN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
metadata-evalN/A
lower-/.f64N/A
pow2N/A
lift-*.f6418.3
Applied rewrites18.3%
Taylor expanded in p around 0
+-commutativeN/A
pow2N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6414.2
Applied rewrites14.2%
NOTE: p, r, and q should be sorted in increasing order before calling this function. (FPCore (p r q) :precision binary64 (let* ((t_0 (+ (fabs r) (fabs p)))) (if (<= q 7.6e+95) (* (+ t_0 (+ (- p) r)) 0.5) (fma t_0 0.5 q))))
assert(p < r && r < q);
double code(double p, double r, double q) {
double t_0 = fabs(r) + fabs(p);
double tmp;
if (q <= 7.6e+95) {
tmp = (t_0 + (-p + r)) * 0.5;
} else {
tmp = fma(t_0, 0.5, q);
}
return tmp;
}
p, r, q = sort([p, r, q]) function code(p, r, q) t_0 = Float64(abs(r) + abs(p)) tmp = 0.0 if (q <= 7.6e+95) tmp = Float64(Float64(t_0 + Float64(Float64(-p) + r)) * 0.5); else tmp = fma(t_0, 0.5, q); end return tmp end
NOTE: p, r, and q should be sorted in increasing order before calling this function.
code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[q, 7.6e+95], N[(N[(t$95$0 + N[((-p) + r), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(t$95$0 * 0.5 + q), $MachinePrecision]]]
\begin{array}{l}
[p, r, q] = \mathsf{sort}([p, r, q])\\
\\
\begin{array}{l}
t_0 := \left|r\right| + \left|p\right|\\
\mathbf{if}\;q \leq 7.6 \cdot 10^{+95}:\\
\;\;\;\;\left(t\_0 + \left(\left(-p\right) + r\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, 0.5, q\right)\\
\end{array}
\end{array}
if q < 7.5999999999999999e95Initial program 49.1%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6428.6
Applied rewrites28.6%
Taylor expanded in p around 0
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
lower-fma.f6434.2
Applied rewrites34.2%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
metadata-eval34.2
Applied rewrites34.2%
lift-fma.f64N/A
mul-1-negN/A
lower-+.f64N/A
lift-neg.f6434.2
Applied rewrites34.2%
if 7.5999999999999999e95 < q Initial program 22.9%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6418.2
Applied rewrites18.2%
Taylor expanded in q around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites69.5%
Taylor expanded in q around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
lift-+.f6469.5
Applied rewrites69.5%
NOTE: p, r, and q should be sorted in increasing order before calling this function. (FPCore (p r q) :precision binary64 (if (<= r 2.6e+93) (fma (+ (fabs r) (fabs p)) 0.5 q) (fma q (/ q r) r)))
assert(p < r && r < q);
double code(double p, double r, double q) {
double tmp;
if (r <= 2.6e+93) {
tmp = fma((fabs(r) + fabs(p)), 0.5, q);
} else {
tmp = fma(q, (q / r), r);
}
return tmp;
}
p, r, q = sort([p, r, q]) function code(p, r, q) tmp = 0.0 if (r <= 2.6e+93) tmp = fma(Float64(abs(r) + abs(p)), 0.5, q); else tmp = fma(q, Float64(q / r), r); end return tmp end
NOTE: p, r, and q should be sorted in increasing order before calling this function. code[p_, r_, q_] := If[LessEqual[r, 2.6e+93], N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] * 0.5 + q), $MachinePrecision], N[(q * N[(q / r), $MachinePrecision] + r), $MachinePrecision]]
\begin{array}{l}
[p, r, q] = \mathsf{sort}([p, r, q])\\
\\
\begin{array}{l}
\mathbf{if}\;r \leq 2.6 \cdot 10^{+93}:\\
\;\;\;\;\mathsf{fma}\left(\left|r\right| + \left|p\right|, 0.5, q\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(q, \frac{q}{r}, r\right)\\
\end{array}
\end{array}
if r < 2.6e93Initial program 48.9%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6425.9
Applied rewrites25.9%
Taylor expanded in q around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.7%
Taylor expanded in q around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
lift-+.f6430.9
Applied rewrites30.9%
if 2.6e93 < r Initial program 15.6%
Taylor expanded in p around 0
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites15.6%
Taylor expanded in q around 0
metadata-evalN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
metadata-evalN/A
lower-/.f64N/A
pow2N/A
lift-*.f6452.2
Applied rewrites52.2%
Taylor expanded in p around 0
+-commutativeN/A
pow2N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6460.1
Applied rewrites60.1%
NOTE: p, r, and q should be sorted in increasing order before calling this function. (FPCore (p r q) :precision binary64 (if (<= r 2.6e+93) (fma (+ (fabs r) (fabs p)) 0.5 q) r))
assert(p < r && r < q);
double code(double p, double r, double q) {
double tmp;
if (r <= 2.6e+93) {
tmp = fma((fabs(r) + fabs(p)), 0.5, q);
} else {
tmp = r;
}
return tmp;
}
p, r, q = sort([p, r, q]) function code(p, r, q) tmp = 0.0 if (r <= 2.6e+93) tmp = fma(Float64(abs(r) + abs(p)), 0.5, q); else tmp = r; end return tmp end
NOTE: p, r, and q should be sorted in increasing order before calling this function. code[p_, r_, q_] := If[LessEqual[r, 2.6e+93], N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] * 0.5 + q), $MachinePrecision], r]
\begin{array}{l}
[p, r, q] = \mathsf{sort}([p, r, q])\\
\\
\begin{array}{l}
\mathbf{if}\;r \leq 2.6 \cdot 10^{+93}:\\
\;\;\;\;\mathsf{fma}\left(\left|r\right| + \left|p\right|, 0.5, q\right)\\
\mathbf{else}:\\
\;\;\;\;r\\
\end{array}
\end{array}
if r < 2.6e93Initial program 48.9%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6425.9
Applied rewrites25.9%
Taylor expanded in q around inf
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.7%
Taylor expanded in q around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
lift-+.f6430.9
Applied rewrites30.9%
if 2.6e93 < r Initial program 15.6%
Taylor expanded in p around 0
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites15.6%
Taylor expanded in r around inf
Applied rewrites59.6%
NOTE: p, r, and q should be sorted in increasing order before calling this function. (FPCore (p r q) :precision binary64 (if (<= r 8.5e+47) q r))
assert(p < r && r < q);
double code(double p, double r, double q) {
double tmp;
if (r <= 8.5e+47) {
tmp = q;
} else {
tmp = r;
}
return tmp;
}
NOTE: p, r, and q should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: tmp
if (r <= 8.5d+47) then
tmp = q
else
tmp = r
end if
code = tmp
end function
assert p < r && r < q;
public static double code(double p, double r, double q) {
double tmp;
if (r <= 8.5e+47) {
tmp = q;
} else {
tmp = r;
}
return tmp;
}
[p, r, q] = sort([p, r, q]) def code(p, r, q): tmp = 0 if r <= 8.5e+47: tmp = q else: tmp = r return tmp
p, r, q = sort([p, r, q]) function code(p, r, q) tmp = 0.0 if (r <= 8.5e+47) tmp = q; else tmp = r; end return tmp end
p, r, q = num2cell(sort([p, r, q])){:}
function tmp_2 = code(p, r, q)
tmp = 0.0;
if (r <= 8.5e+47)
tmp = q;
else
tmp = r;
end
tmp_2 = tmp;
end
NOTE: p, r, and q should be sorted in increasing order before calling this function. code[p_, r_, q_] := If[LessEqual[r, 8.5e+47], q, r]
\begin{array}{l}
[p, r, q] = \mathsf{sort}([p, r, q])\\
\\
\begin{array}{l}
\mathbf{if}\;r \leq 8.5 \cdot 10^{+47}:\\
\;\;\;\;q\\
\mathbf{else}:\\
\;\;\;\;r\\
\end{array}
\end{array}
if r < 8.5000000000000008e47Initial program 48.0%
Taylor expanded in q around inf
Applied rewrites20.0%
if 8.5000000000000008e47 < r Initial program 26.1%
Taylor expanded in p around 0
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites24.6%
Taylor expanded in r around inf
Applied rewrites55.4%
NOTE: p, r, and q should be sorted in increasing order before calling this function. (FPCore (p r q) :precision binary64 q)
assert(p < r && r < q);
double code(double p, double r, double q) {
return q;
}
NOTE: p, r, and q should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = q
end function
assert p < r && r < q;
public static double code(double p, double r, double q) {
return q;
}
[p, r, q] = sort([p, r, q]) def code(p, r, q): return q
p, r, q = sort([p, r, q]) function code(p, r, q) return q end
p, r, q = num2cell(sort([p, r, q])){:}
function tmp = code(p, r, q)
tmp = q;
end
NOTE: p, r, and q should be sorted in increasing order before calling this function. code[p_, r_, q_] := q
\begin{array}{l}
[p, r, q] = \mathsf{sort}([p, r, q])\\
\\
q
\end{array}
Initial program 44.2%
Taylor expanded in q around inf
Applied rewrites19.4%
herbie shell --seed 2025073
(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)))))))