
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (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 = (1.0d0 / x) / (y * (1.0d0 + (z * z)))
end function
public static double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
def code(x, y, z): return (1.0 / x) / (y * (1.0 + (z * z)))
function code(x, y, z) return Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z)))) end
function tmp = code(x, y, z) tmp = (1.0 / x) / (y * (1.0 + (z * z))); end
code[x_, y_, z_] := N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (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 = (1.0d0 / x) / (y * (1.0d0 + (z * z)))
end function
public static double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
def code(x, y, z): return (1.0 / x) / (y * (1.0 + (z * z)))
function code(x, y, z) return Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z)))) end
function tmp = code(x, y, z) tmp = (1.0 / x) / (y * (1.0 + (z * z))); end
code[x_, y_, z_] := N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\end{array}
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
:precision binary64
(*
x_s
(if (<= (* y (+ 1.0 (* z z))) 5e+304)
(/ (/ 1.0 (* (fma z z 1.0) y)) x_m)
(/ 1.0 (* z (* y (* z x_m)))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if ((y * (1.0 + (z * z))) <= 5e+304) {
tmp = (1.0 / (fma(z, z, 1.0) * y)) / x_m;
} else {
tmp = 1.0 / (z * (y * (z * x_m)));
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) tmp = 0.0 if (Float64(y * Float64(1.0 + Float64(z * z))) <= 5e+304) tmp = Float64(Float64(1.0 / Float64(fma(z, z, 1.0) * y)) / x_m); else tmp = Float64(1.0 / Float64(z * Float64(y * Float64(z * x_m)))); end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+304], N[(N[(1.0 / N[(N[(z * z + 1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / x$95$m), $MachinePrecision], N[(1.0 / N[(z * N[(y * N[(z * x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \cdot \left(1 + z \cdot z\right) \leq 5 \cdot 10^{+304}:\\
\;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(z, z, 1\right) \cdot y}}{x\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(z \cdot x\_m\right)\right)}\\
\end{array}
\end{array}
if (*.f64 y (+.f64 #s(literal 1 binary64) (*.f64 z z))) < 4.9999999999999997e304Initial program 93.8%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
associate-/l/N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f6493.3
Applied rewrites93.3%
if 4.9999999999999997e304 < (*.f64 y (+.f64 #s(literal 1 binary64) (*.f64 z z))) Initial program 67.6%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
*-commutativeN/A
pow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f6467.6
Applied rewrites67.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
associate-*l*N/A
lower-*.f64N/A
lift-*.f6487.5
Applied rewrites87.5%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6499.8
Applied rewrites99.8%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
:precision binary64
(*
x_s
(if (<= (* y (+ 1.0 (* z z))) 5e+304)
(/ 1.0 (* (* (fma z z 1.0) y) x_m))
(/ 1.0 (* z (* y (* z x_m)))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if ((y * (1.0 + (z * z))) <= 5e+304) {
tmp = 1.0 / ((fma(z, z, 1.0) * y) * x_m);
} else {
tmp = 1.0 / (z * (y * (z * x_m)));
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) tmp = 0.0 if (Float64(y * Float64(1.0 + Float64(z * z))) <= 5e+304) tmp = Float64(1.0 / Float64(Float64(fma(z, z, 1.0) * y) * x_m)); else tmp = Float64(1.0 / Float64(z * Float64(y * Float64(z * x_m)))); end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+304], N[(1.0 / N[(N[(N[(z * z + 1.0), $MachinePrecision] * y), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(z * N[(y * N[(z * x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \cdot \left(1 + z \cdot z\right) \leq 5 \cdot 10^{+304}:\\
\;\;\;\;\frac{1}{\left(\mathsf{fma}\left(z, z, 1\right) \cdot y\right) \cdot x\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(z \cdot x\_m\right)\right)}\\
\end{array}
\end{array}
if (*.f64 y (+.f64 #s(literal 1 binary64) (*.f64 z z))) < 4.9999999999999997e304Initial program 93.8%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
*-commutativeN/A
pow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f6493.4
Applied rewrites93.4%
if 4.9999999999999997e304 < (*.f64 y (+.f64 #s(literal 1 binary64) (*.f64 z z))) Initial program 67.6%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
*-commutativeN/A
pow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f6467.6
Applied rewrites67.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
associate-*l*N/A
lower-*.f64N/A
lift-*.f6487.5
Applied rewrites87.5%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6499.8
Applied rewrites99.8%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (/ (/ 1.0 (fma (* x_m z) z x_m)) y)))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
return x_s * ((1.0 / fma((x_m * z), z, x_m)) / y);
}
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) return Float64(x_s * Float64(Float64(1.0 / fma(Float64(x_m * z), z, x_m)) / y)) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(N[(1.0 / N[(N[(x$95$m * z), $MachinePrecision] * z + x$95$m), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \frac{\frac{1}{\mathsf{fma}\left(x\_m \cdot z, z, x\_m\right)}}{y}
\end{array}
Initial program 89.9%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
inv-powN/A
lower-pow.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f6489.8
Applied rewrites89.8%
lift-/.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
inv-powN/A
pow2N/A
+-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
*-commutativeN/A
+-commutativeN/A
pow2N/A
lower-*.f64N/A
lift-fma.f6489.5
Applied rewrites89.5%
lift-*.f64N/A
lift-fma.f64N/A
pow2N/A
distribute-lft1-inN/A
*-commutativeN/A
pow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6493.2
Applied rewrites93.2%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
:precision binary64
(*
x_s
(if (<= z 0.85)
(/ (fma (- z) z 1.0) (* y x_m))
(/ 1.0 (* z (* y (* z x_m)))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (z <= 0.85) {
tmp = fma(-z, z, 1.0) / (y * x_m);
} else {
tmp = 1.0 / (z * (y * (z * x_m)));
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) tmp = 0.0 if (z <= 0.85) tmp = Float64(fma(Float64(-z), z, 1.0) / Float64(y * x_m)); else tmp = Float64(1.0 / Float64(z * Float64(y * Float64(z * x_m)))); end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[z, 0.85], N[(N[((-z) * z + 1.0), $MachinePrecision] / N[(y * x$95$m), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(z * N[(y * N[(z * x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq 0.85:\\
\;\;\;\;\frac{\mathsf{fma}\left(-z, z, 1\right)}{y \cdot x\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(z \cdot x\_m\right)\right)}\\
\end{array}
\end{array}
if z < 0.849999999999999978Initial program 93.6%
Taylor expanded in z around 0
associate-*r/N/A
div-add-revN/A
lower-/.f64N/A
mul-1-negN/A
pow2N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6468.1
Applied rewrites68.1%
if 0.849999999999999978 < z Initial program 78.3%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
pow2N/A
associate-/r*N/A
lower-/.f64N/A
*-commutativeN/A
pow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f6477.4
Applied rewrites77.4%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
associate-*l*N/A
lower-*.f64N/A
lift-*.f6490.0
Applied rewrites90.0%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6494.3
Applied rewrites94.3%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (/ (/ 1.0 y) x_m)))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
return x_s * ((1.0 / y) / x_m);
}
x\_m = private
x\_s = private
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
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_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x_s * ((1.0d0 / y) / x_m)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
return x_s * ((1.0 / y) / x_m);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): return x_s * ((1.0 / y) / x_m)
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) return Float64(x_s * Float64(Float64(1.0 / y) / x_m)) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp = code(x_s, x_m, y, z)
tmp = x_s * ((1.0 / y) / x_m);
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(N[(1.0 / y), $MachinePrecision] / x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \frac{\frac{1}{y}}{x\_m}
\end{array}
Initial program 89.9%
Taylor expanded in z around 0
Applied rewrites59.2%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
lower-*.f6459.1
Applied rewrites59.1%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6458.7
pow258.7
distribute-lft-in58.7
*-rgt-identity58.7
+-commutative58.7
pow258.7
associate-*l*58.7
Applied rewrites58.7%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (/ 1.0 (* x_m y))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
return x_s * (1.0 / (x_m * y));
}
x\_m = private
x\_s = private
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
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_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x_s * (1.0d0 / (x_m * y))
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
return x_s * (1.0 / (x_m * y));
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): return x_s * (1.0 / (x_m * y))
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) return Float64(x_s * Float64(1.0 / Float64(x_m * y))) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp = code(x_s, x_m, y, z)
tmp = x_s * (1.0 / (x_m * y));
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(1.0 / N[(x$95$m * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \frac{1}{x\_m \cdot y}
\end{array}
Initial program 89.9%
Taylor expanded in z around 0
Applied rewrites59.2%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
lower-*.f6459.1
Applied rewrites59.1%
Final simplification59.1%
herbie shell --seed 2025085
(FPCore (x y z)
:name "Statistics.Distribution.CauchyLorentz:$cdensity from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (if (< (* y (+ 1 (* z z))) -inf.0) (/ (/ 1 y) (* (+ 1 (* z z)) x)) (if (< (* y (+ 1 (* z z))) 868074325056725200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (/ (/ 1 x) (* (+ 1 (* z z)) y)) (/ (/ 1 y) (* (+ 1 (* z z)) x)))))
(/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))