
(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 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (p r q) :precision binary64 (* (/ 1.0 2.0) (- (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
return (1.0 / 2.0) * ((fabs(p) + fabs(r)) - sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) - sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) - Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q): return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) - math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q) return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) - sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0)))))) end
function tmp = code(p, r, q) tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) - sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0))))); end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r)))
(t_1 (fabs (fmax p r)))
(t_2 (- t_1 (fmax p r)))
(t_3 (- (fmax p r) (fmin p r))))
(if (<= (fabs q) 2.6e-128)
(* (fmin p r) (+ 0.5 (* 0.5 (/ (- t_0 (- (fmax p r) t_1)) (fmin p r)))))
(if (<= (fabs q) 2.6e+34)
(*
(/ 1.0 2.0)
(/
(*
-1.0
(*
(fmin p r)
(fma
-2.0
t_2
(*
-1.0
(/ (fma 4.0 (pow (fabs q) 2.0) (pow t_2 2.0)) (fmin p r))))))
(- (- t_1 (sqrt (fma (* (fabs q) 4.0) (fabs q) (* t_3 t_3)))) t_0)))
(- (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 t_2 = t_1 - fmax(p, r);
double t_3 = fmax(p, r) - fmin(p, r);
double tmp;
if (fabs(q) <= 2.6e-128) {
tmp = fmin(p, r) * (0.5 + (0.5 * ((t_0 - (fmax(p, r) - t_1)) / fmin(p, r))));
} else if (fabs(q) <= 2.6e+34) {
tmp = (1.0 / 2.0) * ((-1.0 * (fmin(p, r) * fma(-2.0, t_2, (-1.0 * (fma(4.0, pow(fabs(q), 2.0), pow(t_2, 2.0)) / fmin(p, r)))))) / ((t_1 - sqrt(fma((fabs(q) * 4.0), fabs(q), (t_3 * t_3)))) - t_0));
} else {
tmp = -fabs(q);
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmin(p, r)) t_1 = abs(fmax(p, r)) t_2 = Float64(t_1 - fmax(p, r)) t_3 = Float64(fmax(p, r) - fmin(p, r)) tmp = 0.0 if (abs(q) <= 2.6e-128) tmp = Float64(fmin(p, r) * Float64(0.5 + Float64(0.5 * Float64(Float64(t_0 - Float64(fmax(p, r) - t_1)) / fmin(p, r))))); elseif (abs(q) <= 2.6e+34) tmp = Float64(Float64(1.0 / 2.0) * Float64(Float64(-1.0 * Float64(fmin(p, r) * fma(-2.0, t_2, Float64(-1.0 * Float64(fma(4.0, (abs(q) ^ 2.0), (t_2 ^ 2.0)) / fmin(p, r)))))) / Float64(Float64(t_1 - sqrt(fma(Float64(abs(q) * 4.0), abs(q), Float64(t_3 * t_3)))) - t_0))); 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]}, Block[{t$95$2 = N[(t$95$1 - N[Max[p, r], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Max[p, r], $MachinePrecision] - N[Min[p, r], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[q], $MachinePrecision], 2.6e-128], N[(N[Min[p, r], $MachinePrecision] * N[(0.5 + N[(0.5 * N[(N[(t$95$0 - N[(N[Max[p, r], $MachinePrecision] - t$95$1), $MachinePrecision]), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[q], $MachinePrecision], 2.6e+34], N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(-1.0 * N[(N[Min[p, r], $MachinePrecision] * N[(-2.0 * t$95$2 + N[(-1.0 * N[(N[(4.0 * N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[t$95$2, 2.0], $MachinePrecision]), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(t$95$1 - N[Sqrt[N[(N[(N[Abs[q], $MachinePrecision] * 4.0), $MachinePrecision] * N[Abs[q], $MachinePrecision] + N[(t$95$3 * t$95$3), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$0), $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|\\
t_2 := t\_1 - \mathsf{max}\left(p, r\right)\\
t_3 := \mathsf{max}\left(p, r\right) - \mathsf{min}\left(p, r\right)\\
\mathbf{if}\;\left|q\right| \leq 2.6 \cdot 10^{-128}:\\
\;\;\;\;\mathsf{min}\left(p, r\right) \cdot \left(0.5 + 0.5 \cdot \frac{t\_0 - \left(\mathsf{max}\left(p, r\right) - t\_1\right)}{\mathsf{min}\left(p, r\right)}\right)\\
\mathbf{elif}\;\left|q\right| \leq 2.6 \cdot 10^{+34}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{-1 \cdot \left(\mathsf{min}\left(p, r\right) \cdot \mathsf{fma}\left(-2, t\_2, -1 \cdot \frac{\mathsf{fma}\left(4, {\left(\left|q\right|\right)}^{2}, {t\_2}^{2}\right)}{\mathsf{min}\left(p, r\right)}\right)\right)}{\left(t\_1 - \sqrt{\mathsf{fma}\left(\left|q\right| \cdot 4, \left|q\right|, t\_3 \cdot t\_3\right)}\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 2.5999999999999998e-128Initial program 23.6%
Taylor expanded in p around -inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites8.4%
Taylor expanded in p around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.0%
Applied rewrites8.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lower--.f6416.4%
Applied rewrites16.4%
if 2.5999999999999998e-128 < q < 2.6e34Initial program 23.6%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
flip-+N/A
lower-unsound-/.f64N/A
Applied rewrites20.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
lower--.f64N/A
lower-fabs.f64N/A
lower-*.f64N/A
lower-/.f64N/A
Applied rewrites26.5%
if 2.6e34 < q Initial program 23.6%
Taylor expanded in q around inf
lower-*.f6419.6%
Applied rewrites19.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6419.6%
Applied rewrites19.6%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r)))
(t_1 (fabs (fmax p r)))
(t_2 (- (fmax p r) t_1))
(t_3 (- (fmin p r) (fmax p r)))
(t_4 (- t_1 (fmax p r))))
(if (<= (fabs q) 2.6e-128)
(* (fmin p r) (+ 0.5 (* 0.5 (/ (- t_0 t_2) (fmin p r)))))
(if (<= (fabs q) 1900000000.0)
(/
(*
0.5
(*
(- (fmin p r))
(fma
t_4
-2.0
(/ (fma t_2 t_4 (* -4.0 (* (fabs q) (fabs q)))) (fmin p r)))))
(- t_1 (+ t_0 (sqrt (fma t_3 t_3 (* (* 4.0 (fabs q)) (fabs q)))))))
(- (fabs q))))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r));
double t_1 = fabs(fmax(p, r));
double t_2 = fmax(p, r) - t_1;
double t_3 = fmin(p, r) - fmax(p, r);
double t_4 = t_1 - fmax(p, r);
double tmp;
if (fabs(q) <= 2.6e-128) {
tmp = fmin(p, r) * (0.5 + (0.5 * ((t_0 - t_2) / fmin(p, r))));
} else if (fabs(q) <= 1900000000.0) {
tmp = (0.5 * (-fmin(p, r) * fma(t_4, -2.0, (fma(t_2, t_4, (-4.0 * (fabs(q) * fabs(q)))) / fmin(p, r))))) / (t_1 - (t_0 + sqrt(fma(t_3, t_3, ((4.0 * fabs(q)) * fabs(q))))));
} else {
tmp = -fabs(q);
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmin(p, r)) t_1 = abs(fmax(p, r)) t_2 = Float64(fmax(p, r) - t_1) t_3 = Float64(fmin(p, r) - fmax(p, r)) t_4 = Float64(t_1 - fmax(p, r)) tmp = 0.0 if (abs(q) <= 2.6e-128) tmp = Float64(fmin(p, r) * Float64(0.5 + Float64(0.5 * Float64(Float64(t_0 - t_2) / fmin(p, r))))); elseif (abs(q) <= 1900000000.0) tmp = Float64(Float64(0.5 * Float64(Float64(-fmin(p, r)) * fma(t_4, -2.0, Float64(fma(t_2, t_4, Float64(-4.0 * Float64(abs(q) * abs(q)))) / fmin(p, r))))) / Float64(t_1 - Float64(t_0 + sqrt(fma(t_3, t_3, Float64(Float64(4.0 * abs(q)) * abs(q))))))); 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]}, Block[{t$95$2 = N[(N[Max[p, r], $MachinePrecision] - t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[Min[p, r], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$1 - N[Max[p, r], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[q], $MachinePrecision], 2.6e-128], N[(N[Min[p, r], $MachinePrecision] * N[(0.5 + N[(0.5 * N[(N[(t$95$0 - t$95$2), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[q], $MachinePrecision], 1900000000.0], N[(N[(0.5 * N[((-N[Min[p, r], $MachinePrecision]) * N[(t$95$4 * -2.0 + N[(N[(t$95$2 * t$95$4 + N[(-4.0 * N[(N[Abs[q], $MachinePrecision] * N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$1 - N[(t$95$0 + N[Sqrt[N[(t$95$3 * t$95$3 + N[(N[(4.0 * N[Abs[q], $MachinePrecision]), $MachinePrecision] * N[Abs[q], $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|\\
t_2 := \mathsf{max}\left(p, r\right) - t\_1\\
t_3 := \mathsf{min}\left(p, r\right) - \mathsf{max}\left(p, r\right)\\
t_4 := t\_1 - \mathsf{max}\left(p, r\right)\\
\mathbf{if}\;\left|q\right| \leq 2.6 \cdot 10^{-128}:\\
\;\;\;\;\mathsf{min}\left(p, r\right) \cdot \left(0.5 + 0.5 \cdot \frac{t\_0 - t\_2}{\mathsf{min}\left(p, r\right)}\right)\\
\mathbf{elif}\;\left|q\right| \leq 1900000000:\\
\;\;\;\;\frac{0.5 \cdot \left(\left(-\mathsf{min}\left(p, r\right)\right) \cdot \mathsf{fma}\left(t\_4, -2, \frac{\mathsf{fma}\left(t\_2, t\_4, -4 \cdot \left(\left|q\right| \cdot \left|q\right|\right)\right)}{\mathsf{min}\left(p, r\right)}\right)\right)}{t\_1 - \left(t\_0 + \sqrt{\mathsf{fma}\left(t\_3, t\_3, \left(4 \cdot \left|q\right|\right) \cdot \left|q\right|\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 2.5999999999999998e-128Initial program 23.6%
Taylor expanded in p around -inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites8.4%
Taylor expanded in p around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.0%
Applied rewrites8.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lower--.f6416.4%
Applied rewrites16.4%
if 2.5999999999999998e-128 < q < 1.9e9Initial program 23.6%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
flip-+N/A
lower-unsound-/.f64N/A
Applied rewrites20.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
lower--.f64N/A
lower-fabs.f64N/A
lower-*.f64N/A
lower-/.f64N/A
Applied rewrites26.5%
Applied rewrites25.0%
if 1.9e9 < q Initial program 23.6%
Taylor expanded in q around inf
lower-*.f6419.6%
Applied rewrites19.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6419.6%
Applied rewrites19.6%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r)))
(t_1 (fabs (fmax p r)))
(t_2 (- (fmax p r) t_1))
(t_3 (- (fmax p r) (fmin p r)))
(t_4 (- t_1 (fmax p r))))
(if (<= (fabs q) 2.6e-128)
(* (fmin p r) (+ 0.5 (* 0.5 (/ (- t_0 t_2) (fmin p r)))))
(if (<= (fabs q) 1900000000.0)
(*
(*
(fma
-2.0
t_4
(/ (fma t_2 t_4 (* (* (fabs q) (fabs q)) -4.0)) (fmin p r)))
(- (fmin p r)))
(/
-0.5
(- (sqrt (fma t_3 t_3 (* (* 4.0 (fabs q)) (fabs q)))) (- t_1 t_0))))
(- (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 t_2 = fmax(p, r) - t_1;
double t_3 = fmax(p, r) - fmin(p, r);
double t_4 = t_1 - fmax(p, r);
double tmp;
if (fabs(q) <= 2.6e-128) {
tmp = fmin(p, r) * (0.5 + (0.5 * ((t_0 - t_2) / fmin(p, r))));
} else if (fabs(q) <= 1900000000.0) {
tmp = (fma(-2.0, t_4, (fma(t_2, t_4, ((fabs(q) * fabs(q)) * -4.0)) / fmin(p, r))) * -fmin(p, r)) * (-0.5 / (sqrt(fma(t_3, t_3, ((4.0 * fabs(q)) * fabs(q)))) - (t_1 - t_0)));
} else {
tmp = -fabs(q);
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmin(p, r)) t_1 = abs(fmax(p, r)) t_2 = Float64(fmax(p, r) - t_1) t_3 = Float64(fmax(p, r) - fmin(p, r)) t_4 = Float64(t_1 - fmax(p, r)) tmp = 0.0 if (abs(q) <= 2.6e-128) tmp = Float64(fmin(p, r) * Float64(0.5 + Float64(0.5 * Float64(Float64(t_0 - t_2) / fmin(p, r))))); elseif (abs(q) <= 1900000000.0) tmp = Float64(Float64(fma(-2.0, t_4, Float64(fma(t_2, t_4, Float64(Float64(abs(q) * abs(q)) * -4.0)) / fmin(p, r))) * Float64(-fmin(p, r))) * Float64(-0.5 / Float64(sqrt(fma(t_3, t_3, Float64(Float64(4.0 * abs(q)) * abs(q)))) - Float64(t_1 - t_0)))); 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]}, Block[{t$95$2 = N[(N[Max[p, r], $MachinePrecision] - t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[Max[p, r], $MachinePrecision] - N[Min[p, r], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$1 - N[Max[p, r], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[q], $MachinePrecision], 2.6e-128], N[(N[Min[p, r], $MachinePrecision] * N[(0.5 + N[(0.5 * N[(N[(t$95$0 - t$95$2), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[q], $MachinePrecision], 1900000000.0], N[(N[(N[(-2.0 * t$95$4 + N[(N[(t$95$2 * t$95$4 + N[(N[(N[Abs[q], $MachinePrecision] * N[Abs[q], $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-N[Min[p, r], $MachinePrecision])), $MachinePrecision] * N[(-0.5 / N[(N[Sqrt[N[(t$95$3 * t$95$3 + N[(N[(4.0 * N[Abs[q], $MachinePrecision]), $MachinePrecision] * N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(t$95$1 - t$95$0), $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|\\
t_2 := \mathsf{max}\left(p, r\right) - t\_1\\
t_3 := \mathsf{max}\left(p, r\right) - \mathsf{min}\left(p, r\right)\\
t_4 := t\_1 - \mathsf{max}\left(p, r\right)\\
\mathbf{if}\;\left|q\right| \leq 2.6 \cdot 10^{-128}:\\
\;\;\;\;\mathsf{min}\left(p, r\right) \cdot \left(0.5 + 0.5 \cdot \frac{t\_0 - t\_2}{\mathsf{min}\left(p, r\right)}\right)\\
\mathbf{elif}\;\left|q\right| \leq 1900000000:\\
\;\;\;\;\left(\mathsf{fma}\left(-2, t\_4, \frac{\mathsf{fma}\left(t\_2, t\_4, \left(\left|q\right| \cdot \left|q\right|\right) \cdot -4\right)}{\mathsf{min}\left(p, r\right)}\right) \cdot \left(-\mathsf{min}\left(p, r\right)\right)\right) \cdot \frac{-0.5}{\sqrt{\mathsf{fma}\left(t\_3, t\_3, \left(4 \cdot \left|q\right|\right) \cdot \left|q\right|\right)} - \left(t\_1 - t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 2.5999999999999998e-128Initial program 23.6%
Taylor expanded in p around -inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites8.4%
Taylor expanded in p around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.0%
Applied rewrites8.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lower--.f6416.4%
Applied rewrites16.4%
if 2.5999999999999998e-128 < q < 1.9e9Initial program 23.6%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
flip-+N/A
lower-unsound-/.f64N/A
Applied rewrites20.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
lower--.f64N/A
lower-fabs.f64N/A
lower-*.f64N/A
lower-/.f64N/A
Applied rewrites26.5%
Applied rewrites25.0%
Applied rewrites25.0%
if 1.9e9 < q Initial program 23.6%
Taylor expanded in q around inf
lower-*.f6419.6%
Applied rewrites19.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6419.6%
Applied rewrites19.6%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (fabs (fmin p r)))
(t_1 (fabs (fmax p r)))
(t_2 (- (fmax p r) (fmin p r))))
(if (<= (fabs q) 2.65e-106)
(* (fmin p r) (+ 0.5 (* 0.5 (/ (- t_0 (- (fmax p r) t_1)) (fmin p r)))))
(if (<= (fabs q) 3.6e+147)
(*
(/ 1.0 2.0)
(/
(* 4.0 (pow (fabs q) 2.0))
(- (- t_1 (sqrt (fma (* (fabs q) 4.0) (fabs q) (* t_2 t_2)))) t_0)))
(* (/ 1.0 2.0) (- (+ t_0 t_1) (* 2.0 (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 t_2 = fmax(p, r) - fmin(p, r);
double tmp;
if (fabs(q) <= 2.65e-106) {
tmp = fmin(p, r) * (0.5 + (0.5 * ((t_0 - (fmax(p, r) - t_1)) / fmin(p, r))));
} else if (fabs(q) <= 3.6e+147) {
tmp = (1.0 / 2.0) * ((4.0 * pow(fabs(q), 2.0)) / ((t_1 - sqrt(fma((fabs(q) * 4.0), fabs(q), (t_2 * t_2)))) - t_0));
} else {
tmp = (1.0 / 2.0) * ((t_0 + t_1) - (2.0 * fabs(q)));
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmin(p, r)) t_1 = abs(fmax(p, r)) t_2 = Float64(fmax(p, r) - fmin(p, r)) tmp = 0.0 if (abs(q) <= 2.65e-106) tmp = Float64(fmin(p, r) * Float64(0.5 + Float64(0.5 * Float64(Float64(t_0 - Float64(fmax(p, r) - t_1)) / fmin(p, r))))); elseif (abs(q) <= 3.6e+147) tmp = Float64(Float64(1.0 / 2.0) * Float64(Float64(4.0 * (abs(q) ^ 2.0)) / Float64(Float64(t_1 - sqrt(fma(Float64(abs(q) * 4.0), abs(q), Float64(t_2 * t_2)))) - t_0))); else tmp = Float64(Float64(1.0 / 2.0) * Float64(Float64(t_0 + t_1) - Float64(2.0 * 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]}, Block[{t$95$2 = N[(N[Max[p, r], $MachinePrecision] - N[Min[p, r], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[q], $MachinePrecision], 2.65e-106], N[(N[Min[p, r], $MachinePrecision] * N[(0.5 + N[(0.5 * N[(N[(t$95$0 - N[(N[Max[p, r], $MachinePrecision] - t$95$1), $MachinePrecision]), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[q], $MachinePrecision], 3.6e+147], N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(4.0 * N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(t$95$1 - N[Sqrt[N[(N[(N[Abs[q], $MachinePrecision] * 4.0), $MachinePrecision] * N[Abs[q], $MachinePrecision] + N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(t$95$0 + t$95$1), $MachinePrecision] - N[(2.0 * N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right|\\
t_1 := \left|\mathsf{max}\left(p, r\right)\right|\\
t_2 := \mathsf{max}\left(p, r\right) - \mathsf{min}\left(p, r\right)\\
\mathbf{if}\;\left|q\right| \leq 2.65 \cdot 10^{-106}:\\
\;\;\;\;\mathsf{min}\left(p, r\right) \cdot \left(0.5 + 0.5 \cdot \frac{t\_0 - \left(\mathsf{max}\left(p, r\right) - t\_1\right)}{\mathsf{min}\left(p, r\right)}\right)\\
\mathbf{elif}\;\left|q\right| \leq 3.6 \cdot 10^{+147}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{4 \cdot {\left(\left|q\right|\right)}^{2}}{\left(t\_1 - \sqrt{\mathsf{fma}\left(\left|q\right| \cdot 4, \left|q\right|, t\_2 \cdot t\_2\right)}\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(\left(t\_0 + t\_1\right) - 2 \cdot \left|q\right|\right)\\
\end{array}
if q < 2.6499999999999999e-106Initial program 23.6%
Taylor expanded in p around -inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites8.4%
Taylor expanded in p around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.0%
Applied rewrites8.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lower--.f6416.4%
Applied rewrites16.4%
if 2.6499999999999999e-106 < q < 3.6000000000000002e147Initial program 23.6%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
flip-+N/A
lower-unsound-/.f64N/A
Applied rewrites20.3%
Taylor expanded in q around inf
lower-*.f64N/A
lower-pow.f6435.1%
Applied rewrites35.1%
if 3.6000000000000002e147 < q Initial program 23.6%
Taylor expanded in q around inf
lower-*.f6418.6%
Applied rewrites18.6%
(FPCore (p r q)
:precision binary64
(let* ((t_0 (- (fmin p r) (fmax p r)))
(t_1 (fabs (fmin p r)))
(t_2 (fabs (fmax p r))))
(if (<= (fabs q) 2.65e-106)
(* (fmin p r) (+ 0.5 (* 0.5 (/ (- t_1 (- (fmax p r) t_2)) (fmin p r)))))
(if (<= (fabs q) 3.6e+147)
(/
(* 2.0 (pow (fabs q) 2.0))
(- t_2 (+ t_1 (sqrt (fma t_0 t_0 (* (* 4.0 (fabs q)) (fabs q)))))))
(* (/ 1.0 2.0) (- (+ t_1 t_2) (* 2.0 (fabs q))))))))double code(double p, double r, double q) {
double t_0 = fmin(p, r) - fmax(p, r);
double t_1 = fabs(fmin(p, r));
double t_2 = fabs(fmax(p, r));
double tmp;
if (fabs(q) <= 2.65e-106) {
tmp = fmin(p, r) * (0.5 + (0.5 * ((t_1 - (fmax(p, r) - t_2)) / fmin(p, r))));
} else if (fabs(q) <= 3.6e+147) {
tmp = (2.0 * pow(fabs(q), 2.0)) / (t_2 - (t_1 + sqrt(fma(t_0, t_0, ((4.0 * fabs(q)) * fabs(q))))));
} else {
tmp = (1.0 / 2.0) * ((t_1 + t_2) - (2.0 * fabs(q)));
}
return tmp;
}
function code(p, r, q) t_0 = Float64(fmin(p, r) - fmax(p, r)) t_1 = abs(fmin(p, r)) t_2 = abs(fmax(p, r)) tmp = 0.0 if (abs(q) <= 2.65e-106) tmp = Float64(fmin(p, r) * Float64(0.5 + Float64(0.5 * Float64(Float64(t_1 - Float64(fmax(p, r) - t_2)) / fmin(p, r))))); elseif (abs(q) <= 3.6e+147) tmp = Float64(Float64(2.0 * (abs(q) ^ 2.0)) / Float64(t_2 - Float64(t_1 + sqrt(fma(t_0, t_0, Float64(Float64(4.0 * abs(q)) * abs(q))))))); else tmp = Float64(Float64(1.0 / 2.0) * Float64(Float64(t_1 + t_2) - Float64(2.0 * abs(q)))); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[(N[Min[p, r], $MachinePrecision] - N[Max[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], 2.65e-106], N[(N[Min[p, r], $MachinePrecision] * N[(0.5 + N[(0.5 * N[(N[(t$95$1 - N[(N[Max[p, r], $MachinePrecision] - t$95$2), $MachinePrecision]), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[q], $MachinePrecision], 3.6e+147], N[(N[(2.0 * N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(t$95$2 - N[(t$95$1 + 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]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(t$95$1 + t$95$2), $MachinePrecision] - N[(2.0 * N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(p, r\right) - \mathsf{max}\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 2.65 \cdot 10^{-106}:\\
\;\;\;\;\mathsf{min}\left(p, r\right) \cdot \left(0.5 + 0.5 \cdot \frac{t\_1 - \left(\mathsf{max}\left(p, r\right) - t\_2\right)}{\mathsf{min}\left(p, r\right)}\right)\\
\mathbf{elif}\;\left|q\right| \leq 3.6 \cdot 10^{+147}:\\
\;\;\;\;\frac{2 \cdot {\left(\left|q\right|\right)}^{2}}{t\_2 - \left(t\_1 + \sqrt{\mathsf{fma}\left(t\_0, t\_0, \left(4 \cdot \left|q\right|\right) \cdot \left|q\right|\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(\left(t\_1 + t\_2\right) - 2 \cdot \left|q\right|\right)\\
\end{array}
if q < 2.6499999999999999e-106Initial program 23.6%
Taylor expanded in p around -inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites8.4%
Taylor expanded in p around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.0%
Applied rewrites8.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lower--.f6416.4%
Applied rewrites16.4%
if 2.6499999999999999e-106 < q < 3.6000000000000002e147Initial program 23.6%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
flip-+N/A
lower-unsound-/.f64N/A
Applied rewrites20.3%
Taylor expanded in p around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
lower--.f64N/A
lower-fabs.f64N/A
lower-*.f64N/A
lower-/.f64N/A
Applied rewrites26.5%
Applied rewrites25.0%
Taylor expanded in q around inf
lower-*.f64N/A
lower-pow.f6432.2%
Applied rewrites32.2%
if 3.6000000000000002e147 < q Initial program 23.6%
Taylor expanded in q around inf
lower-*.f6418.6%
Applied rewrites18.6%
(FPCore (p r q)
:precision binary64
(if (<= (fabs q) 2.5e-19)
(*
(fmin p r)
(+
0.5
(*
0.5
(/ (- (fabs (fmin p r)) (- (fmax p r) (fabs (fmax p r)))) (fmin p r)))))
(- (fabs q))))double code(double p, double r, double q) {
double tmp;
if (fabs(q) <= 2.5e-19) {
tmp = fmin(p, r) * (0.5 + (0.5 * ((fabs(fmin(p, r)) - (fmax(p, r) - fabs(fmax(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) <= 2.5d-19) then
tmp = fmin(p, r) * (0.5d0 + (0.5d0 * ((abs(fmin(p, r)) - (fmax(p, r) - abs(fmax(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) <= 2.5e-19) {
tmp = fmin(p, r) * (0.5 + (0.5 * ((Math.abs(fmin(p, r)) - (fmax(p, r) - Math.abs(fmax(p, r)))) / fmin(p, r))));
} else {
tmp = -Math.abs(q);
}
return tmp;
}
def code(p, r, q): tmp = 0 if math.fabs(q) <= 2.5e-19: tmp = fmin(p, r) * (0.5 + (0.5 * ((math.fabs(fmin(p, r)) - (fmax(p, r) - math.fabs(fmax(p, r)))) / fmin(p, r)))) else: tmp = -math.fabs(q) return tmp
function code(p, r, q) tmp = 0.0 if (abs(q) <= 2.5e-19) tmp = Float64(fmin(p, r) * Float64(0.5 + Float64(0.5 * Float64(Float64(abs(fmin(p, r)) - Float64(fmax(p, r) - abs(fmax(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) <= 2.5e-19) tmp = min(p, r) * (0.5 + (0.5 * ((abs(min(p, r)) - (max(p, r) - abs(max(p, r)))) / min(p, r)))); else tmp = -abs(q); end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[N[Abs[q], $MachinePrecision], 2.5e-19], N[(N[Min[p, r], $MachinePrecision] * N[(0.5 + N[(0.5 * N[(N[(N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision] - N[(N[Max[p, r], $MachinePrecision] - N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $MachinePrecision])]
\begin{array}{l}
\mathbf{if}\;\left|q\right| \leq 2.5 \cdot 10^{-19}:\\
\;\;\;\;\mathsf{min}\left(p, r\right) \cdot \left(0.5 + 0.5 \cdot \frac{\left|\mathsf{min}\left(p, r\right)\right| - \left(\mathsf{max}\left(p, r\right) - \left|\mathsf{max}\left(p, r\right)\right|\right)}{\mathsf{min}\left(p, r\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 2.5000000000000002e-19Initial program 23.6%
Taylor expanded in p around -inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites8.4%
Taylor expanded in p around inf
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-+.f64N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f648.0%
Applied rewrites8.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lower--.f6416.4%
Applied rewrites16.4%
if 2.5000000000000002e-19 < q Initial program 23.6%
Taylor expanded in q around inf
lower-*.f6419.6%
Applied rewrites19.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6419.6%
Applied rewrites19.6%
(FPCore (p r q) :precision binary64 (if (<= (fabs q) 4.2e-62) (- (fabs (fmax p r)) (fmax p r)) (- (fabs q))))
double code(double p, double r, double q) {
double tmp;
if (fabs(q) <= 4.2e-62) {
tmp = 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) <= 4.2d-62) then
tmp = 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) <= 4.2e-62) {
tmp = 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) <= 4.2e-62: tmp = 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) <= 4.2e-62) tmp = Float64(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) <= 4.2e-62) tmp = 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], 4.2e-62], N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $MachinePrecision])]
\begin{array}{l}
\mathbf{if}\;\left|q\right| \leq 4.2 \cdot 10^{-62}:\\
\;\;\;\;\left|\mathsf{max}\left(p, r\right)\right| - \mathsf{max}\left(p, r\right)\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 4.1999999999999998e-62Initial program 23.6%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
flip-+N/A
lower-unsound-/.f64N/A
Applied rewrites20.3%
Taylor expanded in p around -inf
lower--.f64N/A
lower-fabs.f6411.6%
Applied rewrites11.6%
if 4.1999999999999998e-62 < q Initial program 23.6%
Taylor expanded in q around inf
lower-*.f6419.6%
Applied rewrites19.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6419.6%
Applied rewrites19.6%
(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 23.6%
Taylor expanded in q around inf
lower-*.f6419.6%
Applied rewrites19.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6419.6%
Applied rewrites19.6%
herbie shell --seed 2025196
(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)))))))