
(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 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]
\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 (- (fmax p r) (fmin p r)))
(t_1 (fabs (fmin p r)))
(t_2 (fabs (fmax p r))))
(if (<= (fabs q) 1.35e-134)
(*
(- 0.5 (* (/ (+ (- t_2 (fmax p r)) t_1) (fmin p r)) -0.5))
(fmin p r))
(if (<= (fabs q) 7e+133)
(/
(* (* (* (fabs q) (fabs q)) -4.0) 0.5)
(+
(sqrt (fma t_0 t_0 (* (* 4.0 (fabs q)) (fabs q))))
(+ t_1 t_2)))
(- (fabs q))))))double code(double p, double r, double q) {
double t_0 = fmax(p, r) - fmin(p, r);
double t_1 = fabs(fmin(p, r));
double t_2 = fabs(fmax(p, r));
double tmp;
if (fabs(q) <= 1.35e-134) {
tmp = (0.5 - ((((t_2 - fmax(p, r)) + t_1) / fmin(p, r)) * -0.5)) * fmin(p, r);
} else if (fabs(q) <= 7e+133) {
tmp = (((fabs(q) * fabs(q)) * -4.0) * 0.5) / (sqrt(fma(t_0, t_0, ((4.0 * fabs(q)) * fabs(q)))) + (t_1 + t_2));
} else {
tmp = -fabs(q);
}
return tmp;
}
function code(p, r, q) t_0 = Float64(fmax(p, r) - fmin(p, r)) t_1 = abs(fmin(p, r)) t_2 = abs(fmax(p, r)) tmp = 0.0 if (abs(q) <= 1.35e-134) tmp = Float64(Float64(0.5 - Float64(Float64(Float64(Float64(t_2 - fmax(p, r)) + t_1) / fmin(p, r)) * -0.5)) * fmin(p, r)); elseif (abs(q) <= 7e+133) tmp = Float64(Float64(Float64(Float64(abs(q) * abs(q)) * -4.0) * 0.5) / Float64(sqrt(fma(t_0, t_0, Float64(Float64(4.0 * abs(q)) * abs(q)))) + Float64(t_1 + t_2))); else tmp = Float64(-abs(q)); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[(N[Max[p, r], $MachinePrecision] - N[Min[p, r], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Abs[q], $MachinePrecision], 1.35e-134], N[(N[(0.5 - N[(N[(N[(N[(t$95$2 - N[Max[p, r], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * N[Min[p, r], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[q], $MachinePrecision], 7e+133], N[(N[(N[(N[(N[Abs[q], $MachinePrecision] * N[Abs[q], $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision] * 0.5), $MachinePrecision] / N[(N[Sqrt[N[(t$95$0 * t$95$0 + N[(N[(4.0 * N[Abs[q], $MachinePrecision]), $MachinePrecision] * N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(t$95$1 + t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $MachinePrecision])]]]]]
\begin{array}{l}
t_0 := \mathsf{max}\left(p, r\right) - \mathsf{min}\left(p, r\right)\\
t_1 := \left|\mathsf{min}\left(p, r\right)\right|\\
t_2 := \left|\mathsf{max}\left(p, r\right)\right|\\
\mathbf{if}\;\left|q\right| \leq 1.35 \cdot 10^{-134}:\\
\;\;\;\;\left(0.5 - \frac{\left(t\_2 - \mathsf{max}\left(p, r\right)\right) + t\_1}{\mathsf{min}\left(p, r\right)} \cdot -0.5\right) \cdot \mathsf{min}\left(p, r\right)\\
\mathbf{elif}\;\left|q\right| \leq 7 \cdot 10^{+133}:\\
\;\;\;\;\frac{\left(\left(\left|q\right| \cdot \left|q\right|\right) \cdot -4\right) \cdot 0.5}{\sqrt{\mathsf{fma}\left(t\_0, t\_0, \left(4 \cdot \left|q\right|\right) \cdot \left|q\right|\right)} + \left(t\_1 + t\_2\right)}\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 1.3499999999999999e-134Initial program 24.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.3%
Applied rewrites8.3%
metadata-evalN/A
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lift--.f64N/A
lift-/.f64N/A
sub-negate-revN/A
lower-*.f64N/A
Applied rewrites17.4%
if 1.3499999999999999e-134 < q < 6.9999999999999997e133Initial program 24.3%
lift--.f64N/A
flip--N/A
lower-unsound-/.f64N/A
Applied rewrites22.4%
Taylor expanded in q around inf
lower-*.f64N/A
lower-pow.f6441.8%
Applied rewrites41.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites41.8%
if 6.9999999999999997e133 < q Initial program 24.3%
Taylor expanded in q around inf
lower-*.f6418.9%
Applied rewrites18.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6418.9%
Applied rewrites18.9%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r))) (t_1 (fabs (fmax p r))))
(if (<= (fabs q) 1.35e-134)
(*
(- 0.5 (* (/ (+ (- t_1 (fmax p r)) t_0) (fmin p r)) -0.5))
(fmin p r))
(if (<= (fabs q) 1.25e+98)
(/
(* (* (* (fabs q) (fabs q)) -4.0) 0.5)
(*
-1.0
(*
(fmin p r)
(+ 1.0 (* -1.0 (/ (+ (fmax p r) (+ t_0 t_1)) (fmin p r)))))))
(- (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) <= 1.35e-134) {
tmp = (0.5 - ((((t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * -0.5)) * fmin(p, r);
} else if (fabs(q) <= 1.25e+98) {
tmp = (((fabs(q) * fabs(q)) * -4.0) * 0.5) / (-1.0 * (fmin(p, r) * (1.0 + (-1.0 * ((fmax(p, r) + (t_0 + t_1)) / fmin(p, r))))));
} else {
tmp = -fabs(q);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = abs(fmin(p, r))
t_1 = abs(fmax(p, r))
if (abs(q) <= 1.35d-134) then
tmp = (0.5d0 - ((((t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * (-0.5d0))) * fmin(p, r)
else if (abs(q) <= 1.25d+98) then
tmp = (((abs(q) * abs(q)) * (-4.0d0)) * 0.5d0) / ((-1.0d0) * (fmin(p, r) * (1.0d0 + ((-1.0d0) * ((fmax(p, r) + (t_0 + t_1)) / fmin(p, r))))))
else
tmp = -abs(q)
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double t_0 = Math.abs(fmin(p, r));
double t_1 = Math.abs(fmax(p, r));
double tmp;
if (Math.abs(q) <= 1.35e-134) {
tmp = (0.5 - ((((t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * -0.5)) * fmin(p, r);
} else if (Math.abs(q) <= 1.25e+98) {
tmp = (((Math.abs(q) * Math.abs(q)) * -4.0) * 0.5) / (-1.0 * (fmin(p, r) * (1.0 + (-1.0 * ((fmax(p, r) + (t_0 + t_1)) / fmin(p, r))))));
} else {
tmp = -Math.abs(q);
}
return tmp;
}
def code(p, r, q): t_0 = math.fabs(fmin(p, r)) t_1 = math.fabs(fmax(p, r)) tmp = 0 if math.fabs(q) <= 1.35e-134: tmp = (0.5 - ((((t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * -0.5)) * fmin(p, r) elif math.fabs(q) <= 1.25e+98: tmp = (((math.fabs(q) * math.fabs(q)) * -4.0) * 0.5) / (-1.0 * (fmin(p, r) * (1.0 + (-1.0 * ((fmax(p, r) + (t_0 + t_1)) / fmin(p, r)))))) else: tmp = -math.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) <= 1.35e-134) tmp = Float64(Float64(0.5 - Float64(Float64(Float64(Float64(t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * -0.5)) * fmin(p, r)); elseif (abs(q) <= 1.25e+98) tmp = Float64(Float64(Float64(Float64(abs(q) * abs(q)) * -4.0) * 0.5) / Float64(-1.0 * Float64(fmin(p, r) * Float64(1.0 + Float64(-1.0 * Float64(Float64(fmax(p, r) + Float64(t_0 + t_1)) / fmin(p, r))))))); else tmp = Float64(-abs(q)); end return tmp end
function tmp_2 = code(p, r, q) t_0 = abs(min(p, r)); t_1 = abs(max(p, r)); tmp = 0.0; if (abs(q) <= 1.35e-134) tmp = (0.5 - ((((t_1 - max(p, r)) + t_0) / min(p, r)) * -0.5)) * min(p, r); elseif (abs(q) <= 1.25e+98) tmp = (((abs(q) * abs(q)) * -4.0) * 0.5) / (-1.0 * (min(p, r) * (1.0 + (-1.0 * ((max(p, r) + (t_0 + t_1)) / min(p, r)))))); else tmp = -abs(q); end tmp_2 = 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], 1.35e-134], N[(N[(0.5 - N[(N[(N[(N[(t$95$1 - N[Max[p, r], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * N[Min[p, r], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[q], $MachinePrecision], 1.25e+98], N[(N[(N[(N[(N[Abs[q], $MachinePrecision] * N[Abs[q], $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision] * 0.5), $MachinePrecision] / N[(-1.0 * N[(N[Min[p, r], $MachinePrecision] * N[(1.0 + N[(-1.0 * N[(N[(N[Max[p, r], $MachinePrecision] + N[(t$95$0 + t$95$1), $MachinePrecision]), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $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 1.35 \cdot 10^{-134}:\\
\;\;\;\;\left(0.5 - \frac{\left(t\_1 - \mathsf{max}\left(p, r\right)\right) + t\_0}{\mathsf{min}\left(p, r\right)} \cdot -0.5\right) \cdot \mathsf{min}\left(p, r\right)\\
\mathbf{elif}\;\left|q\right| \leq 1.25 \cdot 10^{+98}:\\
\;\;\;\;\frac{\left(\left(\left|q\right| \cdot \left|q\right|\right) \cdot -4\right) \cdot 0.5}{-1 \cdot \left(\mathsf{min}\left(p, r\right) \cdot \left(1 + -1 \cdot \frac{\mathsf{max}\left(p, r\right) + \left(t\_0 + t\_1\right)}{\mathsf{min}\left(p, r\right)}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 1.3499999999999999e-134Initial program 24.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.3%
Applied rewrites8.3%
metadata-evalN/A
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lift--.f64N/A
lift-/.f64N/A
sub-negate-revN/A
lower-*.f64N/A
Applied rewrites17.4%
if 1.3499999999999999e-134 < q < 1.25e98Initial program 24.3%
lift--.f64N/A
flip--N/A
lower-unsound-/.f64N/A
Applied rewrites22.4%
Taylor expanded in q around inf
lower-*.f64N/A
lower-pow.f6441.8%
Applied rewrites41.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites41.8%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6422.3%
Applied rewrites22.3%
if 1.25e98 < q Initial program 24.3%
Taylor expanded in q around inf
lower-*.f6418.9%
Applied rewrites18.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6418.9%
Applied rewrites18.9%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r))) (t_1 (fabs (fmax p r))))
(if (<= (fabs q) 1.35e-134)
(*
(- 0.5 (* (/ (+ (- t_1 (fmax p r)) t_0) (fmin p r)) -0.5))
(fmin p r))
(if (<= (fabs q) 3.2e+149)
(/
(* (* (* (fabs q) (fabs q)) -4.0) 0.5)
(+
(sqrt
(fma (fmax p r) (fmax p r) (* (* 4.0 (fabs q)) (fabs q))))
(+ t_0 t_1)))
(- (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) <= 1.35e-134) {
tmp = (0.5 - ((((t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * -0.5)) * fmin(p, r);
} else if (fabs(q) <= 3.2e+149) {
tmp = (((fabs(q) * fabs(q)) * -4.0) * 0.5) / (sqrt(fma(fmax(p, r), fmax(p, r), ((4.0 * fabs(q)) * fabs(q)))) + (t_0 + t_1));
} else {
tmp = -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) <= 1.35e-134) tmp = Float64(Float64(0.5 - Float64(Float64(Float64(Float64(t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * -0.5)) * fmin(p, r)); elseif (abs(q) <= 3.2e+149) tmp = Float64(Float64(Float64(Float64(abs(q) * abs(q)) * -4.0) * 0.5) / Float64(sqrt(fma(fmax(p, r), fmax(p, r), Float64(Float64(4.0 * abs(q)) * abs(q)))) + Float64(t_0 + t_1))); else tmp = Float64(-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], 1.35e-134], N[(N[(0.5 - N[(N[(N[(N[(t$95$1 - N[Max[p, r], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * N[Min[p, r], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[q], $MachinePrecision], 3.2e+149], N[(N[(N[(N[(N[Abs[q], $MachinePrecision] * N[Abs[q], $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision] * 0.5), $MachinePrecision] / N[(N[Sqrt[N[(N[Max[p, r], $MachinePrecision] * N[Max[p, r], $MachinePrecision] + N[(N[(4.0 * N[Abs[q], $MachinePrecision]), $MachinePrecision] * N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(t$95$0 + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $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 1.35 \cdot 10^{-134}:\\
\;\;\;\;\left(0.5 - \frac{\left(t\_1 - \mathsf{max}\left(p, r\right)\right) + t\_0}{\mathsf{min}\left(p, r\right)} \cdot -0.5\right) \cdot \mathsf{min}\left(p, r\right)\\
\mathbf{elif}\;\left|q\right| \leq 3.2 \cdot 10^{+149}:\\
\;\;\;\;\frac{\left(\left(\left|q\right| \cdot \left|q\right|\right) \cdot -4\right) \cdot 0.5}{\sqrt{\mathsf{fma}\left(\mathsf{max}\left(p, r\right), \mathsf{max}\left(p, r\right), \left(4 \cdot \left|q\right|\right) \cdot \left|q\right|\right)} + \left(t\_0 + t\_1\right)}\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 1.3499999999999999e-134Initial program 24.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.3%
Applied rewrites8.3%
metadata-evalN/A
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lift--.f64N/A
lift-/.f64N/A
sub-negate-revN/A
lower-*.f64N/A
Applied rewrites17.4%
if 1.3499999999999999e-134 < q < 3.2000000000000002e149Initial program 24.3%
lift--.f64N/A
flip--N/A
lower-unsound-/.f64N/A
Applied rewrites22.4%
Taylor expanded in q around inf
lower-*.f64N/A
lower-pow.f6441.8%
Applied rewrites41.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites41.8%
Taylor expanded in p around 0
Applied rewrites37.6%
Taylor expanded in p around 0
Applied rewrites38.2%
if 3.2000000000000002e149 < q Initial program 24.3%
Taylor expanded in q around inf
lower-*.f6418.9%
Applied rewrites18.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6418.9%
Applied rewrites18.9%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r))) (t_1 (fabs (fmax p r))))
(if (<= (fabs q) 5.5e-87)
(*
(- 0.5 (* (/ (+ (- t_1 (fmax p r)) t_0) (fmin p r)) -0.5))
(fmin p r))
(if (<= (fabs q) 5e+150)
(/
(* (* (* (fabs q) (fabs q)) -4.0) 0.5)
(+ (* 2.0 (fabs q)) (+ t_0 t_1)))
(- (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) <= 5.5e-87) {
tmp = (0.5 - ((((t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * -0.5)) * fmin(p, r);
} else if (fabs(q) <= 5e+150) {
tmp = (((fabs(q) * fabs(q)) * -4.0) * 0.5) / ((2.0 * fabs(q)) + (t_0 + t_1));
} else {
tmp = -fabs(q);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = abs(fmin(p, r))
t_1 = abs(fmax(p, r))
if (abs(q) <= 5.5d-87) then
tmp = (0.5d0 - ((((t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * (-0.5d0))) * fmin(p, r)
else if (abs(q) <= 5d+150) then
tmp = (((abs(q) * abs(q)) * (-4.0d0)) * 0.5d0) / ((2.0d0 * abs(q)) + (t_0 + t_1))
else
tmp = -abs(q)
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double t_0 = Math.abs(fmin(p, r));
double t_1 = Math.abs(fmax(p, r));
double tmp;
if (Math.abs(q) <= 5.5e-87) {
tmp = (0.5 - ((((t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * -0.5)) * fmin(p, r);
} else if (Math.abs(q) <= 5e+150) {
tmp = (((Math.abs(q) * Math.abs(q)) * -4.0) * 0.5) / ((2.0 * Math.abs(q)) + (t_0 + t_1));
} else {
tmp = -Math.abs(q);
}
return tmp;
}
def code(p, r, q): t_0 = math.fabs(fmin(p, r)) t_1 = math.fabs(fmax(p, r)) tmp = 0 if math.fabs(q) <= 5.5e-87: tmp = (0.5 - ((((t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * -0.5)) * fmin(p, r) elif math.fabs(q) <= 5e+150: tmp = (((math.fabs(q) * math.fabs(q)) * -4.0) * 0.5) / ((2.0 * math.fabs(q)) + (t_0 + t_1)) else: tmp = -math.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) <= 5.5e-87) tmp = Float64(Float64(0.5 - Float64(Float64(Float64(Float64(t_1 - fmax(p, r)) + t_0) / fmin(p, r)) * -0.5)) * fmin(p, r)); elseif (abs(q) <= 5e+150) tmp = Float64(Float64(Float64(Float64(abs(q) * abs(q)) * -4.0) * 0.5) / Float64(Float64(2.0 * abs(q)) + Float64(t_0 + t_1))); else tmp = Float64(-abs(q)); end return tmp end
function tmp_2 = code(p, r, q) t_0 = abs(min(p, r)); t_1 = abs(max(p, r)); tmp = 0.0; if (abs(q) <= 5.5e-87) tmp = (0.5 - ((((t_1 - max(p, r)) + t_0) / min(p, r)) * -0.5)) * min(p, r); elseif (abs(q) <= 5e+150) tmp = (((abs(q) * abs(q)) * -4.0) * 0.5) / ((2.0 * abs(q)) + (t_0 + t_1)); else tmp = -abs(q); end tmp_2 = 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], 5.5e-87], N[(N[(0.5 - N[(N[(N[(N[(t$95$1 - N[Max[p, r], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * N[Min[p, r], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[q], $MachinePrecision], 5e+150], N[(N[(N[(N[(N[Abs[q], $MachinePrecision] * N[Abs[q], $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision] * 0.5), $MachinePrecision] / N[(N[(2.0 * N[Abs[q], $MachinePrecision]), $MachinePrecision] + N[(t$95$0 + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $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 5.5 \cdot 10^{-87}:\\
\;\;\;\;\left(0.5 - \frac{\left(t\_1 - \mathsf{max}\left(p, r\right)\right) + t\_0}{\mathsf{min}\left(p, r\right)} \cdot -0.5\right) \cdot \mathsf{min}\left(p, r\right)\\
\mathbf{elif}\;\left|q\right| \leq 5 \cdot 10^{+150}:\\
\;\;\;\;\frac{\left(\left(\left|q\right| \cdot \left|q\right|\right) \cdot -4\right) \cdot 0.5}{2 \cdot \left|q\right| + \left(t\_0 + t\_1\right)}\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 5.5000000000000004e-87Initial program 24.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.3%
Applied rewrites8.3%
metadata-evalN/A
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lift--.f64N/A
lift-/.f64N/A
sub-negate-revN/A
lower-*.f64N/A
Applied rewrites17.4%
if 5.5000000000000004e-87 < q < 5.0000000000000001e150Initial program 24.3%
lift--.f64N/A
flip--N/A
lower-unsound-/.f64N/A
Applied rewrites22.4%
Taylor expanded in q around inf
lower-*.f64N/A
lower-pow.f6441.8%
Applied rewrites41.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites41.8%
Taylor expanded in q around inf
lower-*.f6429.3%
Applied rewrites29.3%
if 5.0000000000000001e150 < q Initial program 24.3%
Taylor expanded in q around inf
lower-*.f6418.9%
Applied rewrites18.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6418.9%
Applied rewrites18.9%
(FPCore (p r q)
:precision binary64
(if (<= (fabs q) 3.4e-8)
(*
(-
0.5
(*
(/
(+ (- (fabs (fmax p r)) (fmax p r)) (fabs (fmin p r)))
(fmin p r))
-0.5))
(fmin p r))
(- (fabs q))))double code(double p, double r, double q) {
double tmp;
if (fabs(q) <= 3.4e-8) {
tmp = (0.5 - ((((fabs(fmax(p, r)) - fmax(p, r)) + fabs(fmin(p, r))) / fmin(p, r)) * -0.5)) * fmin(p, r);
} else {
tmp = -fabs(q);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: tmp
if (abs(q) <= 3.4d-8) then
tmp = (0.5d0 - ((((abs(fmax(p, r)) - fmax(p, r)) + abs(fmin(p, r))) / fmin(p, r)) * (-0.5d0))) * fmin(p, r)
else
tmp = -abs(q)
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (Math.abs(q) <= 3.4e-8) {
tmp = (0.5 - ((((Math.abs(fmax(p, r)) - fmax(p, r)) + Math.abs(fmin(p, r))) / fmin(p, r)) * -0.5)) * fmin(p, r);
} else {
tmp = -Math.abs(q);
}
return tmp;
}
def code(p, r, q): tmp = 0 if math.fabs(q) <= 3.4e-8: tmp = (0.5 - ((((math.fabs(fmax(p, r)) - fmax(p, r)) + math.fabs(fmin(p, r))) / fmin(p, r)) * -0.5)) * fmin(p, r) else: tmp = -math.fabs(q) return tmp
function code(p, r, q) tmp = 0.0 if (abs(q) <= 3.4e-8) tmp = Float64(Float64(0.5 - Float64(Float64(Float64(Float64(abs(fmax(p, r)) - fmax(p, r)) + abs(fmin(p, r))) / fmin(p, r)) * -0.5)) * fmin(p, r)); else tmp = Float64(-abs(q)); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (abs(q) <= 3.4e-8) tmp = (0.5 - ((((abs(max(p, r)) - max(p, r)) + abs(min(p, r))) / min(p, r)) * -0.5)) * min(p, r); else tmp = -abs(q); end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[N[Abs[q], $MachinePrecision], 3.4e-8], N[(N[(0.5 - N[(N[(N[(N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision] + N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * N[Min[p, r], $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $MachinePrecision])]
\begin{array}{l}
\mathbf{if}\;\left|q\right| \leq 3.4 \cdot 10^{-8}:\\
\;\;\;\;\left(0.5 - \frac{\left(\left|\mathsf{max}\left(p, r\right)\right| - \mathsf{max}\left(p, r\right)\right) + \left|\mathsf{min}\left(p, r\right)\right|}{\mathsf{min}\left(p, r\right)} \cdot -0.5\right) \cdot \mathsf{min}\left(p, r\right)\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 3.4e-8Initial program 24.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.3%
Applied rewrites8.3%
metadata-evalN/A
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lift--.f64N/A
lift-/.f64N/A
sub-negate-revN/A
lower-*.f64N/A
Applied rewrites17.4%
if 3.4e-8 < q Initial program 24.3%
Taylor expanded in q around inf
lower-*.f6418.9%
Applied rewrites18.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6418.9%
Applied rewrites18.9%
(FPCore (p r q)
:precision binary64
(let* ((t_0
(*
0.5
(- (+ (fabs (fmin p r)) (fabs (fmax p r))) (fmax p r)))))
(if (<= (fabs q) 1.05e-168)
(fma 0.5 (fmin p r) t_0)
(if (<= (fabs q) 7.2e-69) t_0 (- (fabs q))))))double code(double p, double r, double q) {
double t_0 = 0.5 * ((fabs(fmin(p, r)) + fabs(fmax(p, r))) - fmax(p, r));
double tmp;
if (fabs(q) <= 1.05e-168) {
tmp = fma(0.5, fmin(p, r), t_0);
} else if (fabs(q) <= 7.2e-69) {
tmp = t_0;
} else {
tmp = -fabs(q);
}
return tmp;
}
function code(p, r, q) t_0 = Float64(0.5 * Float64(Float64(abs(fmin(p, r)) + abs(fmax(p, r))) - fmax(p, r))) tmp = 0.0 if (abs(q) <= 1.05e-168) tmp = fma(0.5, fmin(p, r), t_0); elseif (abs(q) <= 7.2e-69) tmp = t_0; else tmp = Float64(-abs(q)); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[(0.5 * N[(N[(N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision] + N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[q], $MachinePrecision], 1.05e-168], N[(0.5 * N[Min[p, r], $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[N[Abs[q], $MachinePrecision], 7.2e-69], t$95$0, (-N[Abs[q], $MachinePrecision])]]]
\begin{array}{l}
t_0 := 0.5 \cdot \left(\left(\left|\mathsf{min}\left(p, r\right)\right| + \left|\mathsf{max}\left(p, r\right)\right|\right) - \mathsf{max}\left(p, r\right)\right)\\
\mathbf{if}\;\left|q\right| \leq 1.05 \cdot 10^{-168}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \mathsf{min}\left(p, r\right), t\_0\right)\\
\mathbf{elif}\;\left|q\right| \leq 7.2 \cdot 10^{-69}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 1.05e-168Initial program 24.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.3%
Applied rewrites8.3%
Taylor expanded in p 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-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.4%
Applied rewrites8.4%
if 1.05e-168 < q < 7.2000000000000004e-69Initial program 24.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.3%
Applied rewrites8.3%
Taylor expanded in p around 0
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f646.7%
Applied rewrites6.7%
if 7.2000000000000004e-69 < q Initial program 24.3%
Taylor expanded in q around inf
lower-*.f6418.9%
Applied rewrites18.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6418.9%
Applied rewrites18.9%
(FPCore (p r q) :precision binary64 (if (<= (fabs q) 7.2e-69) (* 0.5 (- (+ (fabs (fmin p r)) (fabs (fmax p r))) (fmax p r))) (- (fabs q))))
double code(double p, double r, double q) {
double tmp;
if (fabs(q) <= 7.2e-69) {
tmp = 0.5 * ((fabs(fmin(p, r)) + fabs(fmax(p, r))) - fmax(p, r));
} else {
tmp = -fabs(q);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: tmp
if (abs(q) <= 7.2d-69) then
tmp = 0.5d0 * ((abs(fmin(p, r)) + abs(fmax(p, r))) - fmax(p, r))
else
tmp = -abs(q)
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (Math.abs(q) <= 7.2e-69) {
tmp = 0.5 * ((Math.abs(fmin(p, r)) + Math.abs(fmax(p, r))) - fmax(p, r));
} else {
tmp = -Math.abs(q);
}
return tmp;
}
def code(p, r, q): tmp = 0 if math.fabs(q) <= 7.2e-69: tmp = 0.5 * ((math.fabs(fmin(p, r)) + math.fabs(fmax(p, r))) - fmax(p, r)) else: tmp = -math.fabs(q) return tmp
function code(p, r, q) tmp = 0.0 if (abs(q) <= 7.2e-69) tmp = Float64(0.5 * Float64(Float64(abs(fmin(p, r)) + abs(fmax(p, r))) - fmax(p, r))); else tmp = Float64(-abs(q)); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (abs(q) <= 7.2e-69) tmp = 0.5 * ((abs(min(p, r)) + abs(max(p, r))) - max(p, r)); else tmp = -abs(q); end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[N[Abs[q], $MachinePrecision], 7.2e-69], N[(0.5 * N[(N[(N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision] + N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $MachinePrecision])]
\begin{array}{l}
\mathbf{if}\;\left|q\right| \leq 7.2 \cdot 10^{-69}:\\
\;\;\;\;0.5 \cdot \left(\left(\left|\mathsf{min}\left(p, r\right)\right| + \left|\mathsf{max}\left(p, r\right)\right|\right) - \mathsf{max}\left(p, r\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 7.2000000000000004e-69Initial program 24.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.3%
Applied rewrites8.3%
Taylor expanded in p around 0
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f646.7%
Applied rewrites6.7%
if 7.2000000000000004e-69 < q Initial program 24.3%
Taylor expanded in q around inf
lower-*.f6418.9%
Applied rewrites18.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6418.9%
Applied rewrites18.9%
(FPCore (p r q) :precision binary64 (if (<= (fabs q) 5.6e-112) (* (* -0.5 (/ (fmax p r) (fmin p r))) (fmin p r)) (- (fabs q))))
double code(double p, double r, double q) {
double tmp;
if (fabs(q) <= 5.6e-112) {
tmp = (-0.5 * (fmax(p, r) / fmin(p, r))) * fmin(p, r);
} else {
tmp = -fabs(q);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: tmp
if (abs(q) <= 5.6d-112) then
tmp = ((-0.5d0) * (fmax(p, r) / fmin(p, r))) * fmin(p, r)
else
tmp = -abs(q)
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (Math.abs(q) <= 5.6e-112) {
tmp = (-0.5 * (fmax(p, r) / fmin(p, r))) * fmin(p, r);
} else {
tmp = -Math.abs(q);
}
return tmp;
}
def code(p, r, q): tmp = 0 if math.fabs(q) <= 5.6e-112: tmp = (-0.5 * (fmax(p, r) / fmin(p, r))) * fmin(p, r) else: tmp = -math.fabs(q) return tmp
function code(p, r, q) tmp = 0.0 if (abs(q) <= 5.6e-112) tmp = Float64(Float64(-0.5 * Float64(fmax(p, r) / fmin(p, r))) * fmin(p, r)); else tmp = Float64(-abs(q)); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if (abs(q) <= 5.6e-112) tmp = (-0.5 * (max(p, r) / min(p, r))) * min(p, r); else tmp = -abs(q); end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[N[Abs[q], $MachinePrecision], 5.6e-112], N[(N[(-0.5 * N[(N[Max[p, r], $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Min[p, r], $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $MachinePrecision])]
\begin{array}{l}
\mathbf{if}\;\left|q\right| \leq 5.6 \cdot 10^{-112}:\\
\;\;\;\;\left(-0.5 \cdot \frac{\mathsf{max}\left(p, r\right)}{\mathsf{min}\left(p, r\right)}\right) \cdot \mathsf{min}\left(p, r\right)\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 5.6000000000000005e-112Initial program 24.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.3%
Applied rewrites8.3%
metadata-evalN/A
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lift--.f64N/A
lift-/.f64N/A
sub-negate-revN/A
lower-*.f64N/A
Applied rewrites17.4%
Taylor expanded in p around inf
Applied rewrites4.3%
Taylor expanded in r around inf
lower-*.f64N/A
lower-/.f646.4%
Applied rewrites6.4%
if 5.6000000000000005e-112 < q Initial program 24.3%
Taylor expanded in q around inf
lower-*.f6418.9%
Applied rewrites18.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6418.9%
Applied rewrites18.9%
(FPCore (p r q) :precision binary64 (- (fabs q)))
double code(double p, double r, double q) {
return -fabs(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 = -abs(q)
end function
public static double code(double p, double r, double q) {
return -Math.abs(q);
}
def code(p, r, q): return -math.fabs(q)
function code(p, r, q) return Float64(-abs(q)) end
function tmp = code(p, r, q) tmp = -abs(q); end
code[p_, r_, q_] := (-N[Abs[q], $MachinePrecision])
-\left|q\right|
Initial program 24.3%
Taylor expanded in q around inf
lower-*.f6418.9%
Applied rewrites18.9%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6418.9%
Applied rewrites18.9%
herbie shell --seed 2025213
(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)))))))