
(FPCore (x y z) :precision binary64 (sqrt (+ (* x x) (+ (* y y) (* z z)))))
double code(double x, double y, double z) {
return sqrt(((x * x) + ((y * y) + (z * z))));
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = sqrt(((x * x) + ((y * y) + (z * z))))
end function
public static double code(double x, double y, double z) {
return Math.sqrt(((x * x) + ((y * y) + (z * z))));
}
def code(x, y, z): return math.sqrt(((x * x) + ((y * y) + (z * z))))
function code(x, y, z) return sqrt(Float64(Float64(x * x) + Float64(Float64(y * y) + Float64(z * z)))) end
function tmp = code(x, y, z) tmp = sqrt(((x * x) + ((y * y) + (z * z)))); end
code[x_, y_, z_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(N[(y * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{x \cdot x + \left(y \cdot y + z \cdot z\right)}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (sqrt (+ (* x x) (+ (* y y) (* z z)))))
double code(double x, double y, double z) {
return sqrt(((x * x) + ((y * y) + (z * z))));
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = sqrt(((x * x) + ((y * y) + (z * z))))
end function
public static double code(double x, double y, double z) {
return Math.sqrt(((x * x) + ((y * y) + (z * z))));
}
def code(x, y, z): return math.sqrt(((x * x) + ((y * y) + (z * z))))
function code(x, y, z) return sqrt(Float64(Float64(x * x) + Float64(Float64(y * y) + Float64(z * z)))) end
function tmp = code(x, y, z) tmp = sqrt(((x * x) + ((y * y) + (z * z)))); end
code[x_, y_, z_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(N[(y * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{x \cdot x + \left(y \cdot y + z \cdot z\right)}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (fmin (fabs x) (fabs z)))
(t_1 (fmax (fabs x) (fabs z)))
(t_2 (fmax (fabs y) t_1))
(t_3 (fmin (fabs y) t_1)))
(+ t_2 (134-z0z1z2z3z4 (/ 1/2 t_2) t_3 t_3 (- t_0) t_0))))\begin{array}{l}
t_0 := \mathsf{min}\left(\left|x\right|, \left|z\right|\right)\\
t_1 := \mathsf{max}\left(\left|x\right|, \left|z\right|\right)\\
t_2 := \mathsf{max}\left(\left|y\right|, t\_1\right)\\
t_3 := \mathsf{min}\left(\left|y\right|, t\_1\right)\\
t\_2 + \mathsf{134\_z0z1z2z3z4}\left(\left(\frac{\frac{1}{2}}{t\_2}\right), t\_3, t\_3, \left(-t\_0\right), t\_0\right)
\end{array}
Initial program 44.5%
Taylor expanded in z around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-pow.f64N/A
lower-pow.f64N/A
lower-pow.f6415.3%
Applied rewrites15.3%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-pow.f64N/A
pow2N/A
associate-/r*N/A
sum-to-mult-revN/A
lower-+.f64N/A
lower-/.f64N/A
Applied rewrites16.0%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
lift-*.f64N/A
lift-neg.f64N/A
lower-134-z0z1z2z3z4N/A
lower-/.f6418.5%
Applied rewrites18.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (fmin (fabs x) (fabs z)))
(t_1 (fmax (fabs x) (fabs z)))
(t_2 (fmin (fabs y) t_1))
(t_3 (fmax (fabs y) t_1)))
(+ t_3 (/ (* (+ (* t_2 t_2) (* t_0 t_0)) 1/2) t_3))))double code(double x, double y, double z) {
double t_0 = fmin(fabs(x), fabs(z));
double t_1 = fmax(fabs(x), fabs(z));
double t_2 = fmin(fabs(y), t_1);
double t_3 = fmax(fabs(y), t_1);
return t_3 + ((((t_2 * t_2) + (t_0 * t_0)) * 0.5) / t_3);
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
t_0 = fmin(abs(x), abs(z))
t_1 = fmax(abs(x), abs(z))
t_2 = fmin(abs(y), t_1)
t_3 = fmax(abs(y), t_1)
code = t_3 + ((((t_2 * t_2) + (t_0 * t_0)) * 0.5d0) / t_3)
end function
public static double code(double x, double y, double z) {
double t_0 = fmin(Math.abs(x), Math.abs(z));
double t_1 = fmax(Math.abs(x), Math.abs(z));
double t_2 = fmin(Math.abs(y), t_1);
double t_3 = fmax(Math.abs(y), t_1);
return t_3 + ((((t_2 * t_2) + (t_0 * t_0)) * 0.5) / t_3);
}
def code(x, y, z): t_0 = fmin(math.fabs(x), math.fabs(z)) t_1 = fmax(math.fabs(x), math.fabs(z)) t_2 = fmin(math.fabs(y), t_1) t_3 = fmax(math.fabs(y), t_1) return t_3 + ((((t_2 * t_2) + (t_0 * t_0)) * 0.5) / t_3)
function code(x, y, z) t_0 = fmin(abs(x), abs(z)) t_1 = fmax(abs(x), abs(z)) t_2 = fmin(abs(y), t_1) t_3 = fmax(abs(y), t_1) return Float64(t_3 + Float64(Float64(Float64(Float64(t_2 * t_2) + Float64(t_0 * t_0)) * 0.5) / t_3)) end
function tmp = code(x, y, z) t_0 = min(abs(x), abs(z)); t_1 = max(abs(x), abs(z)); t_2 = min(abs(y), t_1); t_3 = max(abs(y), t_1); tmp = t_3 + ((((t_2 * t_2) + (t_0 * t_0)) * 0.5) / t_3); end
code[x_, y_, z_] := Block[{t$95$0 = N[Min[N[Abs[x], $MachinePrecision], N[Abs[z], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Max[N[Abs[x], $MachinePrecision], N[Abs[z], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Min[N[Abs[y], $MachinePrecision], t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[Max[N[Abs[y], $MachinePrecision], t$95$1], $MachinePrecision]}, N[(t$95$3 + N[(N[(N[(N[(t$95$2 * t$95$2), $MachinePrecision] + N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] * 1/2), $MachinePrecision] / t$95$3), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(\left|x\right|, \left|z\right|\right)\\
t_1 := \mathsf{max}\left(\left|x\right|, \left|z\right|\right)\\
t_2 := \mathsf{min}\left(\left|y\right|, t\_1\right)\\
t_3 := \mathsf{max}\left(\left|y\right|, t\_1\right)\\
t\_3 + \frac{\left(t\_2 \cdot t\_2 + t\_0 \cdot t\_0\right) \cdot \frac{1}{2}}{t\_3}
\end{array}
Initial program 44.5%
Taylor expanded in z around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-pow.f64N/A
lower-pow.f64N/A
lower-pow.f6415.3%
Applied rewrites15.3%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-pow.f64N/A
pow2N/A
associate-/r*N/A
sum-to-mult-revN/A
lower-+.f64N/A
lower-/.f64N/A
Applied rewrites16.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (fmin (fmin x y) z))
(t_1 (fmax (fmax x y) (fmax (fmin x y) z))))
(sqrt (+ (* t_0 t_0) (* t_1 t_1)))))double code(double x, double y, double z) {
double t_0 = fmin(fmin(x, y), z);
double t_1 = fmax(fmax(x, y), fmax(fmin(x, y), z));
return sqrt(((t_0 * t_0) + (t_1 * t_1)));
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
t_0 = fmin(fmin(x, y), z)
t_1 = fmax(fmax(x, y), fmax(fmin(x, y), z))
code = sqrt(((t_0 * t_0) + (t_1 * t_1)))
end function
public static double code(double x, double y, double z) {
double t_0 = fmin(fmin(x, y), z);
double t_1 = fmax(fmax(x, y), fmax(fmin(x, y), z));
return Math.sqrt(((t_0 * t_0) + (t_1 * t_1)));
}
def code(x, y, z): t_0 = fmin(fmin(x, y), z) t_1 = fmax(fmax(x, y), fmax(fmin(x, y), z)) return math.sqrt(((t_0 * t_0) + (t_1 * t_1)))
function code(x, y, z) t_0 = fmin(fmin(x, y), z) t_1 = fmax(fmax(x, y), fmax(fmin(x, y), z)) return sqrt(Float64(Float64(t_0 * t_0) + Float64(t_1 * t_1))) end
function tmp = code(x, y, z) t_0 = min(min(x, y), z); t_1 = max(max(x, y), max(min(x, y), z)); tmp = sqrt(((t_0 * t_0) + (t_1 * t_1))); end
code[x_, y_, z_] := Block[{t$95$0 = N[Min[N[Min[x, y], $MachinePrecision], z], $MachinePrecision]}, Block[{t$95$1 = N[Max[N[Max[x, y], $MachinePrecision], N[Max[N[Min[x, y], $MachinePrecision], z], $MachinePrecision]], $MachinePrecision]}, N[Sqrt[N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(\mathsf{min}\left(x, y\right), z\right)\\
t_1 := \mathsf{max}\left(\mathsf{max}\left(x, y\right), \mathsf{max}\left(\mathsf{min}\left(x, y\right), z\right)\right)\\
\sqrt{t\_0 \cdot t\_0 + t\_1 \cdot t\_1}
\end{array}
Initial program 44.5%
Taylor expanded in y around 0
lower-pow.f6430.6%
Applied rewrites30.6%
lift-pow.f64N/A
pow2N/A
lower-*.f6430.6%
Applied rewrites30.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fmax (fabs x) (fabs z)))) (* 1/2 (* t_0 (/ t_0 (fmin (fabs x) (fabs z)))))))
double code(double x, double y, double z) {
double t_0 = fmax(fabs(x), fabs(z));
return 0.5 * (t_0 * (t_0 / fmin(fabs(x), fabs(z))));
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
t_0 = fmax(abs(x), abs(z))
code = 0.5d0 * (t_0 * (t_0 / fmin(abs(x), abs(z))))
end function
public static double code(double x, double y, double z) {
double t_0 = fmax(Math.abs(x), Math.abs(z));
return 0.5 * (t_0 * (t_0 / fmin(Math.abs(x), Math.abs(z))));
}
def code(x, y, z): t_0 = fmax(math.fabs(x), math.fabs(z)) return 0.5 * (t_0 * (t_0 / fmin(math.fabs(x), math.fabs(z))))
function code(x, y, z) t_0 = fmax(abs(x), abs(z)) return Float64(0.5 * Float64(t_0 * Float64(t_0 / fmin(abs(x), abs(z))))) end
function tmp = code(x, y, z) t_0 = max(abs(x), abs(z)); tmp = 0.5 * (t_0 * (t_0 / min(abs(x), abs(z)))); end
code[x_, y_, z_] := Block[{t$95$0 = N[Max[N[Abs[x], $MachinePrecision], N[Abs[z], $MachinePrecision]], $MachinePrecision]}, N[(1/2 * N[(t$95$0 * N[(t$95$0 / N[Min[N[Abs[x], $MachinePrecision], N[Abs[z], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \mathsf{max}\left(\left|x\right|, \left|z\right|\right)\\
\frac{1}{2} \cdot \left(t\_0 \cdot \frac{t\_0}{\mathsf{min}\left(\left|x\right|, \left|z\right|\right)}\right)
\end{array}
Initial program 44.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-pow.f64N/A
lower-pow.f64N/A
lower-pow.f6416.1%
Applied rewrites16.1%
Taylor expanded in z around inf
lower-*.f64N/A
lower-/.f64N/A
lower-pow.f643.0%
Applied rewrites3.0%
lift-/.f64N/A
lift-pow.f64N/A
pow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f643.1%
Applied rewrites3.1%
(FPCore (x y z) :precision binary64 (* (fabs x) 1))
double code(double x, double y, double z) {
return fabs(x) * 1.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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = abs(x) * 1.0d0
end function
public static double code(double x, double y, double z) {
return Math.abs(x) * 1.0;
}
def code(x, y, z): return math.fabs(x) * 1.0
function code(x, y, z) return Float64(abs(x) * 1.0) end
function tmp = code(x, y, z) tmp = abs(x) * 1.0; end
code[x_, y_, z_] := N[(N[Abs[x], $MachinePrecision] * 1), $MachinePrecision]
\left|x\right| \cdot 1
Initial program 44.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-pow.f64N/A
lower-pow.f64N/A
lower-pow.f6416.1%
Applied rewrites16.1%
Taylor expanded in x around inf
Applied rewrites18.9%
(FPCore (x y z) :precision binary64 (- (fmin (fmin x y) z)))
double code(double x, double y, double z) {
return -fmin(fmin(x, y), z);
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -fmin(fmin(x, y), z)
end function
public static double code(double x, double y, double z) {
return -fmin(fmin(x, y), z);
}
def code(x, y, z): return -fmin(fmin(x, y), z)
function code(x, y, z) return Float64(-fmin(fmin(x, y), z)) end
function tmp = code(x, y, z) tmp = -min(min(x, y), z); end
code[x_, y_, z_] := (-N[Min[N[Min[x, y], $MachinePrecision], z], $MachinePrecision])
-\mathsf{min}\left(\mathsf{min}\left(x, y\right), z\right)
Initial program 44.5%
Taylor expanded in x around -inf
lower-*.f6419.0%
Applied rewrites19.0%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6419.0%
Applied rewrites19.0%
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (x y z)
:name "bug366 (missed optimization)"
:precision binary64
(sqrt (+ (* x x) (+ (* y y) (* z z)))))