
(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 5 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 (fmax p r)))
(t_1 (fabs (fmin p r)))
(t_2 (- (fmax p r) (fmin p r))))
(if (<= (fabs q) 2.6e-61)
(*
-1.0
(*
(fmin p r)
(- (* -0.5 (/ (+ (- t_0 (fmax p r)) t_1) (fmin p r))) 0.5)))
(if (<= (fabs q) 3.8e+147)
(/
(* -1.0 (pow (fabs q) 2.0))
(-
(* t_0 0.5)
(* (- t_1 (sqrt (fma (* (fabs q) 4.0) (fabs q) (* t_2 t_2)))) 0.5)))
(* (- (+ t_0 t_1) (+ (fabs q) (fabs q))) 0.5)))))double code(double p, double r, double q) {
double t_0 = fabs(fmax(p, r));
double t_1 = fabs(fmin(p, r));
double t_2 = fmax(p, r) - fmin(p, r);
double tmp;
if (fabs(q) <= 2.6e-61) {
tmp = -1.0 * (fmin(p, r) * ((-0.5 * (((t_0 - fmax(p, r)) + t_1) / fmin(p, r))) - 0.5));
} else if (fabs(q) <= 3.8e+147) {
tmp = (-1.0 * pow(fabs(q), 2.0)) / ((t_0 * 0.5) - ((t_1 - sqrt(fma((fabs(q) * 4.0), fabs(q), (t_2 * t_2)))) * 0.5));
} else {
tmp = ((t_0 + t_1) - (fabs(q) + fabs(q))) * 0.5;
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmax(p, r)) t_1 = abs(fmin(p, r)) t_2 = Float64(fmax(p, r) - fmin(p, r)) tmp = 0.0 if (abs(q) <= 2.6e-61) tmp = Float64(-1.0 * Float64(fmin(p, r) * Float64(Float64(-0.5 * Float64(Float64(Float64(t_0 - fmax(p, r)) + t_1) / fmin(p, r))) - 0.5))); elseif (abs(q) <= 3.8e+147) tmp = Float64(Float64(-1.0 * (abs(q) ^ 2.0)) / Float64(Float64(t_0 * 0.5) - Float64(Float64(t_1 - sqrt(fma(Float64(abs(q) * 4.0), abs(q), Float64(t_2 * t_2)))) * 0.5))); else tmp = Float64(Float64(Float64(t_0 + t_1) - Float64(abs(q) + abs(q))) * 0.5); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[Min[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.6e-61], N[(-1.0 * N[(N[Min[p, r], $MachinePrecision] * N[(N[(-0.5 * N[(N[(N[(t$95$0 - N[Max[p, r], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[q], $MachinePrecision], 3.8e+147], N[(N[(-1.0 * N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(t$95$0 * 0.5), $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] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$0 + t$95$1), $MachinePrecision] - N[(N[Abs[q], $MachinePrecision] + N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]]]
\begin{array}{l}
t_0 := \left|\mathsf{max}\left(p, r\right)\right|\\
t_1 := \left|\mathsf{min}\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.6 \cdot 10^{-61}:\\
\;\;\;\;-1 \cdot \left(\mathsf{min}\left(p, r\right) \cdot \left(-0.5 \cdot \frac{\left(t\_0 - \mathsf{max}\left(p, r\right)\right) + t\_1}{\mathsf{min}\left(p, r\right)} - 0.5\right)\right)\\
\mathbf{elif}\;\left|q\right| \leq 3.8 \cdot 10^{+147}:\\
\;\;\;\;\frac{-1 \cdot {\left(\left|q\right|\right)}^{2}}{t\_0 \cdot 0.5 - \left(t\_1 - \sqrt{\mathsf{fma}\left(\left|q\right| \cdot 4, \left|q\right|, t\_2 \cdot t\_2\right)}\right) \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(t\_0 + t\_1\right) - \left(\left|q\right| + \left|q\right|\right)\right) \cdot 0.5\\
\end{array}
if q < 2.6000000000000001e-61Initial program 23.6%
Taylor expanded in p around -inf
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
Applied rewrites8.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6416.4%
Applied rewrites16.4%
if 2.6000000000000001e-61 < q < 3.7999999999999997e147Initial program 23.6%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
distribute-rgt-inN/A
flip-+N/A
Applied rewrites20.1%
Taylor expanded in q around inf
lower-*.f64N/A
lower-pow.f6434.9%
Applied rewrites34.9%
if 3.7999999999999997e147 < q Initial program 23.6%
Taylor expanded in q around inf
lower-*.f6418.6%
Applied rewrites18.6%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-*.f64N/A
count-2-revN/A
lower-+.f64N/A
lower-+.f64N/A
Applied rewrites18.6%
(FPCore (p r q)
:precision binary64
(if (<= (fabs q) 2.5e-19)
(*
-1.0
(*
(fmin p r)
(-
(*
-0.5
(/ (+ (- (fabs (fmax p r)) (fmax p r)) (fabs (fmin p r))) (fmin p r)))
0.5)))
(- (fabs q))))double code(double p, double r, double q) {
double tmp;
if (fabs(q) <= 2.5e-19) {
tmp = -1.0 * (fmin(p, r) * ((-0.5 * (((fabs(fmax(p, r)) - fmax(p, r)) + fabs(fmin(p, r))) / fmin(p, r))) - 0.5));
} 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 = (-1.0d0) * (fmin(p, r) * (((-0.5d0) * (((abs(fmax(p, r)) - fmax(p, r)) + abs(fmin(p, r))) / fmin(p, r))) - 0.5d0))
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 = -1.0 * (fmin(p, r) * ((-0.5 * (((Math.abs(fmax(p, r)) - fmax(p, r)) + Math.abs(fmin(p, r))) / fmin(p, r))) - 0.5));
} else {
tmp = -Math.abs(q);
}
return tmp;
}
def code(p, r, q): tmp = 0 if math.fabs(q) <= 2.5e-19: tmp = -1.0 * (fmin(p, r) * ((-0.5 * (((math.fabs(fmax(p, r)) - fmax(p, r)) + math.fabs(fmin(p, r))) / fmin(p, r))) - 0.5)) else: tmp = -math.fabs(q) return tmp
function code(p, r, q) tmp = 0.0 if (abs(q) <= 2.5e-19) tmp = Float64(-1.0 * Float64(fmin(p, r) * Float64(Float64(-0.5 * Float64(Float64(Float64(abs(fmax(p, r)) - fmax(p, r)) + abs(fmin(p, r))) / fmin(p, r))) - 0.5))); 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 = -1.0 * (min(p, r) * ((-0.5 * (((abs(max(p, r)) - max(p, r)) + abs(min(p, r))) / min(p, r))) - 0.5)); else tmp = -abs(q); end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[N[Abs[q], $MachinePrecision], 2.5e-19], N[(-1.0 * N[(N[Min[p, r], $MachinePrecision] * N[(N[(-0.5 * 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]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $MachinePrecision])]
\begin{array}{l}
\mathbf{if}\;\left|q\right| \leq 2.5 \cdot 10^{-19}:\\
\;\;\;\;-1 \cdot \left(\mathsf{min}\left(p, r\right) \cdot \left(-0.5 \cdot \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)} - 0.5\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
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
Applied rewrites8.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/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) 2.6e-61)
(fma
0.5
(fmin p r)
(* 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) <= 2.6e-61) {
tmp = fma(0.5, fmin(p, r), (0.5 * ((fabs(fmin(p, r)) + fabs(fmax(p, r))) - fmax(p, r))));
} else {
tmp = -fabs(q);
}
return tmp;
}
function code(p, r, q) tmp = 0.0 if (abs(q) <= 2.6e-61) tmp = fma(0.5, fmin(p, r), 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
code[p_, r_, q_] := If[LessEqual[N[Abs[q], $MachinePrecision], 2.6e-61], N[(0.5 * N[Min[p, r], $MachinePrecision] + 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]), $MachinePrecision], (-N[Abs[q], $MachinePrecision])]
\begin{array}{l}
\mathbf{if}\;\left|q\right| \leq 2.6 \cdot 10^{-61}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \mathsf{min}\left(p, r\right), 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)\right)\\
\mathbf{else}:\\
\;\;\;\;-\left|q\right|\\
\end{array}
if q < 2.6000000000000001e-61Initial program 23.6%
Taylor expanded in p around -inf
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
Applied rewrites8.0%
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.1%
Applied rewrites8.1%
if 2.6000000000000001e-61 < 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-83) (* 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) <= 4.2e-83) {
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) <= 4.2d-83) 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) <= 4.2e-83) {
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) <= 4.2e-83: 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) <= 4.2e-83) 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) <= 4.2e-83) 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], 4.2e-83], 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 4.2 \cdot 10^{-83}:\\
\;\;\;\;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 < 4.1999999999999998e-83Initial program 23.6%
Taylor expanded in p around -inf
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
Applied rewrites8.0%
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.1%
Applied rewrites6.1%
if 4.1999999999999998e-83 < 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)))))))