
(FPCore (p r q) :precision binary64 (* (/ 1.0 2.0) (- (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
return (1.0 / 2.0) * ((fabs(p) + fabs(r)) - sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) - sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) - Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q): return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) - math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q) return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) - sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0)))))) end
function tmp = code(p, r, q) tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) - sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0))))); end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
\end{array}
Herbie found 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}
q_m = (fabs.f64 q) (FPCore (p r q_m) :precision binary64 (if (<= q_m 2.65e-15) (* -1.0 (/ (pow q_m 2.0) (sqrt (pow (- p r) 2.0)))) (- q_m)))
q_m = fabs(q);
double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 2.65e-15) {
tmp = -1.0 * (pow(q_m, 2.0) / sqrt(pow((p - r), 2.0)));
} else {
tmp = -q_m;
}
return tmp;
}
q_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if (q_m <= 2.65d-15) then
tmp = (-1.0d0) * ((q_m ** 2.0d0) / sqrt(((p - r) ** 2.0d0)))
else
tmp = -q_m
end if
code = tmp
end function
q_m = Math.abs(q);
public static double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 2.65e-15) {
tmp = -1.0 * (Math.pow(q_m, 2.0) / Math.sqrt(Math.pow((p - r), 2.0)));
} else {
tmp = -q_m;
}
return tmp;
}
q_m = math.fabs(q) def code(p, r, q_m): tmp = 0 if q_m <= 2.65e-15: tmp = -1.0 * (math.pow(q_m, 2.0) / math.sqrt(math.pow((p - r), 2.0))) else: tmp = -q_m return tmp
q_m = abs(q) function code(p, r, q_m) tmp = 0.0 if (q_m <= 2.65e-15) tmp = Float64(-1.0 * Float64((q_m ^ 2.0) / sqrt((Float64(p - r) ^ 2.0)))); else tmp = Float64(-q_m); end return tmp end
q_m = abs(q); function tmp_2 = code(p, r, q_m) tmp = 0.0; if (q_m <= 2.65e-15) tmp = -1.0 * ((q_m ^ 2.0) / sqrt(((p - r) ^ 2.0))); else tmp = -q_m; end tmp_2 = tmp; end
q_m = N[Abs[q], $MachinePrecision] code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 2.65e-15], N[(-1.0 * N[(N[Power[q$95$m, 2.0], $MachinePrecision] / N[Sqrt[N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-q$95$m)]
\begin{array}{l}
q_m = \left|q\right|
\\
\begin{array}{l}
\mathbf{if}\;q\_m \leq 2.65 \cdot 10^{-15}:\\
\;\;\;\;-1 \cdot \frac{{q\_m}^{2}}{\sqrt{{\left(p - r\right)}^{2}}}\\
\mathbf{else}:\\
\;\;\;\;-q\_m\\
\end{array}
\end{array}
if q < 2.6500000000000001e-15Initial program 24.5%
Taylor expanded in q around 0
Applied rewrites18.7%
Taylor expanded in q around inf
Applied rewrites28.0%
if 2.6500000000000001e-15 < q Initial program 24.5%
Taylor expanded in q around inf
Applied rewrites36.0%
Applied rewrites36.0%
q_m = (fabs.f64 q) (FPCore (p r q_m) :precision binary64 (if (<= q_m 6.5e-16) (fma -1.0 (/ (pow q_m 2.0) (* r (+ 1.0 (* -1.0 (/ p r))))) (* 1.0 (- p p))) (- q_m)))
q_m = fabs(q);
double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 6.5e-16) {
tmp = fma(-1.0, (pow(q_m, 2.0) / (r * (1.0 + (-1.0 * (p / r))))), (1.0 * (p - p)));
} else {
tmp = -q_m;
}
return tmp;
}
q_m = abs(q) function code(p, r, q_m) tmp = 0.0 if (q_m <= 6.5e-16) tmp = fma(-1.0, Float64((q_m ^ 2.0) / Float64(r * Float64(1.0 + Float64(-1.0 * Float64(p / r))))), Float64(1.0 * Float64(p - p))); else tmp = Float64(-q_m); end return tmp end
q_m = N[Abs[q], $MachinePrecision] code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 6.5e-16], N[(-1.0 * N[(N[Power[q$95$m, 2.0], $MachinePrecision] / N[(r * N[(1.0 + N[(-1.0 * N[(p / r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 * N[(p - p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-q$95$m)]
\begin{array}{l}
q_m = \left|q\right|
\\
\begin{array}{l}
\mathbf{if}\;q\_m \leq 6.5 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{{q\_m}^{2}}{r \cdot \left(1 + -1 \cdot \frac{p}{r}\right)}, 1 \cdot \left(p - p\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-q\_m\\
\end{array}
\end{array}
if q < 6.50000000000000011e-16Initial program 24.5%
Taylor expanded in q around 0
Applied rewrites18.7%
Taylor expanded in r around inf
Applied rewrites13.6%
Taylor expanded in r around inf
Applied rewrites16.5%
Applied rewrites26.6%
if 6.50000000000000011e-16 < q Initial program 24.5%
Taylor expanded in q around inf
Applied rewrites36.0%
Applied rewrites36.0%
q_m = (fabs.f64 q) (FPCore (p r q_m) :precision binary64 (if (<= q_m 8.5e-77) (* (- (- p r) (fma q_m 4.0 (- p r))) 1.0) (* 0.5 (- (+ (fabs p) (fabs r)) (* 2.0 q_m)))))
q_m = fabs(q);
double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 8.5e-77) {
tmp = ((p - r) - fma(q_m, 4.0, (p - r))) * 1.0;
} else {
tmp = 0.5 * ((fabs(p) + fabs(r)) - (2.0 * q_m));
}
return tmp;
}
q_m = abs(q) function code(p, r, q_m) tmp = 0.0 if (q_m <= 8.5e-77) tmp = Float64(Float64(Float64(p - r) - fma(q_m, 4.0, Float64(p - r))) * 1.0); else tmp = Float64(0.5 * Float64(Float64(abs(p) + abs(r)) - Float64(2.0 * q_m))); end return tmp end
q_m = N[Abs[q], $MachinePrecision] code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 8.5e-77], N[(N[(N[(p - r), $MachinePrecision] - N[(q$95$m * 4.0 + N[(p - r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision], N[(0.5 * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[(2.0 * q$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
q_m = \left|q\right|
\\
\begin{array}{l}
\mathbf{if}\;q\_m \leq 8.5 \cdot 10^{-77}:\\
\;\;\;\;\left(\left(p - r\right) - \mathsf{fma}\left(q\_m, 4, p - r\right)\right) \cdot 1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(\left|p\right| + \left|r\right|\right) - 2 \cdot q\_m\right)\\
\end{array}
\end{array}
if q < 8.4999999999999998e-77Initial program 24.5%
Applied rewrites24.2%
if 8.4999999999999998e-77 < q Initial program 24.5%
Taylor expanded in q around inf
Applied rewrites35.3%
Applied rewrites35.3%
q_m = (fabs.f64 q) (FPCore (p r q_m) :precision binary64 (if (<= q_m 8.5e-77) (* 0.5 0.0) (* 0.5 (- (+ (fabs p) (fabs r)) (* 2.0 q_m)))))
q_m = fabs(q);
double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 8.5e-77) {
tmp = 0.5 * 0.0;
} else {
tmp = 0.5 * ((fabs(p) + fabs(r)) - (2.0 * q_m));
}
return tmp;
}
q_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if (q_m <= 8.5d-77) then
tmp = 0.5d0 * 0.0d0
else
tmp = 0.5d0 * ((abs(p) + abs(r)) - (2.0d0 * q_m))
end if
code = tmp
end function
q_m = Math.abs(q);
public static double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 8.5e-77) {
tmp = 0.5 * 0.0;
} else {
tmp = 0.5 * ((Math.abs(p) + Math.abs(r)) - (2.0 * q_m));
}
return tmp;
}
q_m = math.fabs(q) def code(p, r, q_m): tmp = 0 if q_m <= 8.5e-77: tmp = 0.5 * 0.0 else: tmp = 0.5 * ((math.fabs(p) + math.fabs(r)) - (2.0 * q_m)) return tmp
q_m = abs(q) function code(p, r, q_m) tmp = 0.0 if (q_m <= 8.5e-77) tmp = Float64(0.5 * 0.0); else tmp = Float64(0.5 * Float64(Float64(abs(p) + abs(r)) - Float64(2.0 * q_m))); end return tmp end
q_m = abs(q); function tmp_2 = code(p, r, q_m) tmp = 0.0; if (q_m <= 8.5e-77) tmp = 0.5 * 0.0; else tmp = 0.5 * ((abs(p) + abs(r)) - (2.0 * q_m)); end tmp_2 = tmp; end
q_m = N[Abs[q], $MachinePrecision] code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 8.5e-77], N[(0.5 * 0.0), $MachinePrecision], N[(0.5 * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[(2.0 * q$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
q_m = \left|q\right|
\\
\begin{array}{l}
\mathbf{if}\;q\_m \leq 8.5 \cdot 10^{-77}:\\
\;\;\;\;0.5 \cdot 0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(\left|p\right| + \left|r\right|\right) - 2 \cdot q\_m\right)\\
\end{array}
\end{array}
if q < 8.4999999999999998e-77Initial program 24.5%
Taylor expanded in p around -inf
Applied rewrites4.2%
Applied rewrites19.0%
if 8.4999999999999998e-77 < q Initial program 24.5%
Taylor expanded in q around inf
Applied rewrites35.3%
Applied rewrites35.3%
q_m = (fabs.f64 q) (FPCore (p r q_m) :precision binary64 (if (<= (* 4.0 (pow q_m 2.0)) 5e-183) (* 0.5 0.0) (- q_m)))
q_m = fabs(q);
double code(double p, double r, double q_m) {
double tmp;
if ((4.0 * pow(q_m, 2.0)) <= 5e-183) {
tmp = 0.5 * 0.0;
} else {
tmp = -q_m;
}
return tmp;
}
q_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if ((4.0d0 * (q_m ** 2.0d0)) <= 5d-183) then
tmp = 0.5d0 * 0.0d0
else
tmp = -q_m
end if
code = tmp
end function
q_m = Math.abs(q);
public static double code(double p, double r, double q_m) {
double tmp;
if ((4.0 * Math.pow(q_m, 2.0)) <= 5e-183) {
tmp = 0.5 * 0.0;
} else {
tmp = -q_m;
}
return tmp;
}
q_m = math.fabs(q) def code(p, r, q_m): tmp = 0 if (4.0 * math.pow(q_m, 2.0)) <= 5e-183: tmp = 0.5 * 0.0 else: tmp = -q_m return tmp
q_m = abs(q) function code(p, r, q_m) tmp = 0.0 if (Float64(4.0 * (q_m ^ 2.0)) <= 5e-183) tmp = Float64(0.5 * 0.0); else tmp = Float64(-q_m); end return tmp end
q_m = abs(q); function tmp_2 = code(p, r, q_m) tmp = 0.0; if ((4.0 * (q_m ^ 2.0)) <= 5e-183) tmp = 0.5 * 0.0; else tmp = -q_m; end tmp_2 = tmp; end
q_m = N[Abs[q], $MachinePrecision] code[p_, r_, q$95$m_] := If[LessEqual[N[(4.0 * N[Power[q$95$m, 2.0], $MachinePrecision]), $MachinePrecision], 5e-183], N[(0.5 * 0.0), $MachinePrecision], (-q$95$m)]
\begin{array}{l}
q_m = \left|q\right|
\\
\begin{array}{l}
\mathbf{if}\;4 \cdot {q\_m}^{2} \leq 5 \cdot 10^{-183}:\\
\;\;\;\;0.5 \cdot 0\\
\mathbf{else}:\\
\;\;\;\;-q\_m\\
\end{array}
\end{array}
if (*.f64 #s(literal 4 binary64) (pow.f64 q #s(literal 2 binary64))) < 5.0000000000000002e-183Initial program 24.5%
Taylor expanded in p around -inf
Applied rewrites4.2%
Applied rewrites19.0%
if 5.0000000000000002e-183 < (*.f64 #s(literal 4 binary64) (pow.f64 q #s(literal 2 binary64))) Initial program 24.5%
Taylor expanded in q around inf
Applied rewrites36.0%
Applied rewrites36.0%
q_m = (fabs.f64 q) (FPCore (p r q_m) :precision binary64 (- q_m))
q_m = fabs(q);
double code(double p, double r, double q_m) {
return -q_m;
}
q_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
code = -q_m
end function
q_m = Math.abs(q);
public static double code(double p, double r, double q_m) {
return -q_m;
}
q_m = math.fabs(q) def code(p, r, q_m): return -q_m
q_m = abs(q) function code(p, r, q_m) return Float64(-q_m) end
q_m = abs(q); function tmp = code(p, r, q_m) tmp = -q_m; end
q_m = N[Abs[q], $MachinePrecision] code[p_, r_, q$95$m_] := (-q$95$m)
\begin{array}{l}
q_m = \left|q\right|
\\
-q\_m
\end{array}
Initial program 24.5%
Taylor expanded in q around inf
Applied rewrites36.0%
Applied rewrites36.0%
q_m = (fabs.f64 q) (FPCore (p r q_m) :precision binary64 q_m)
q_m = fabs(q);
double code(double p, double r, double q_m) {
return q_m;
}
q_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
code = q_m
end function
q_m = Math.abs(q);
public static double code(double p, double r, double q_m) {
return q_m;
}
q_m = math.fabs(q) def code(p, r, q_m): return q_m
q_m = abs(q) function code(p, r, q_m) return q_m end
q_m = abs(q); function tmp = code(p, r, q_m) tmp = q_m; end
q_m = N[Abs[q], $MachinePrecision] code[p_, r_, q$95$m_] := q$95$m
\begin{array}{l}
q_m = \left|q\right|
\\
q\_m
\end{array}
Initial program 24.5%
Taylor expanded in q around inf
Applied rewrites36.0%
Applied rewrites36.0%
Applied rewrites3.3%
herbie shell --seed 2025159
(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)))))))