
(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 9 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}
(FPCore (x y z) :precision binary64 (/ 1.0 (fma (* (* x z) y) z (* y x))))
double code(double x, double y, double z) {
return 1.0 / fma(((x * z) * y), z, (y * x));
}
function code(x, y, z) return Float64(1.0 / fma(Float64(Float64(x * z) * y), z, Float64(y * x))) end
code[x_, y_, z_] := N[(1.0 / N[(N[(N[(x * z), $MachinePrecision] * y), $MachinePrecision] * z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(\left(x \cdot z\right) \cdot y, z, y \cdot x\right)}
\end{array}
Initial program 91.5%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6491.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6491.2
Applied rewrites91.2%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-inN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
distribute-rgt-inN/A
*-rgt-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
lift-fma.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites97.0%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lower-*.f6498.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.5
Applied rewrites98.5%
(FPCore (x y z) :precision binary64 (if (<= (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))) 0.0) (/ 1.0 (* (* (* x y) z) z)) (/ 1.0 (* (fma (* z y) z y) x))))
double code(double x, double y, double z) {
double tmp;
if (((1.0 / x) / (y * (1.0 + (z * z)))) <= 0.0) {
tmp = 1.0 / (((x * y) * z) * z);
} else {
tmp = 1.0 / (fma((z * y), z, y) * x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z)))) <= 0.0) tmp = Float64(1.0 / Float64(Float64(Float64(x * y) * z) * z)); else tmp = Float64(1.0 / Float64(fma(Float64(z * y), z, y) * x)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(1.0 / N[(N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(z * y), $MachinePrecision] * z + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \leq 0:\\
\;\;\;\;\frac{1}{\left(\left(x \cdot y\right) \cdot z\right) \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(z \cdot y, z, y\right) \cdot x}\\
\end{array}
\end{array}
if (/.f64 (/.f64 #s(literal 1 binary64) x) (*.f64 y (+.f64 #s(literal 1 binary64) (*.f64 z z)))) < 0.0Initial program 87.8%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6487.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6487.9
Applied rewrites87.9%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-inN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
distribute-rgt-inN/A
*-rgt-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
lift-fma.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites97.0%
Taylor expanded in z around inf
associate-*r*N/A
distribute-rgt-outN/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
unpow2N/A
*-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites72.9%
if 0.0 < (/.f64 (/.f64 #s(literal 1 binary64) x) (*.f64 y (+.f64 #s(literal 1 binary64) (*.f64 z z)))) Initial program 99.5%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f6499.5
Applied rewrites99.5%
lift-/.f64N/A
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft1-inN/A
lift-*.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-/r*N/A
*-commutativeN/A
lift-*.f64N/A
lift-/.f6498.3
Applied rewrites98.3%
(FPCore (x y z) :precision binary64 (if (<= (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))) 2e-319) (/ 1.0 (* (* (* x y) z) z)) (/ 1.0 (* (* y (fma z z 1.0)) x))))
double code(double x, double y, double z) {
double tmp;
if (((1.0 / x) / (y * (1.0 + (z * z)))) <= 2e-319) {
tmp = 1.0 / (((x * y) * z) * z);
} else {
tmp = 1.0 / ((y * fma(z, z, 1.0)) * x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z)))) <= 2e-319) tmp = Float64(1.0 / Float64(Float64(Float64(x * y) * z) * z)); else tmp = Float64(1.0 / Float64(Float64(y * fma(z, z, 1.0)) * x)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-319], N[(1.0 / N[(N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(y * N[(z * z + 1.0), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \leq 2 \cdot 10^{-319}:\\
\;\;\;\;\frac{1}{\left(\left(x \cdot y\right) \cdot z\right) \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(y \cdot \mathsf{fma}\left(z, z, 1\right)\right) \cdot x}\\
\end{array}
\end{array}
if (/.f64 (/.f64 #s(literal 1 binary64) x) (*.f64 y (+.f64 #s(literal 1 binary64) (*.f64 z z)))) < 1.99998e-319Initial program 87.9%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6487.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6487.9
Applied rewrites87.9%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-inN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
distribute-rgt-inN/A
*-rgt-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
lift-fma.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites96.9%
Taylor expanded in z around inf
associate-*r*N/A
distribute-rgt-outN/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
unpow2N/A
*-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites72.9%
if 1.99998e-319 < (/.f64 (/.f64 #s(literal 1 binary64) x) (*.f64 y (+.f64 #s(literal 1 binary64) (*.f64 z z)))) Initial program 99.5%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6498.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6498.5
Applied rewrites98.5%
(FPCore (x y z) :precision binary64 (if (<= y 8.6e-100) (/ 1.0 (* (fma (* z y) z y) x)) (/ 1.0 (fma z (* z (* y x)) (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 8.6e-100) {
tmp = 1.0 / (fma((z * y), z, y) * x);
} else {
tmp = 1.0 / fma(z, (z * (y * x)), (y * x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 8.6e-100) tmp = Float64(1.0 / Float64(fma(Float64(z * y), z, y) * x)); else tmp = Float64(1.0 / fma(z, Float64(z * Float64(y * x)), Float64(y * x))); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 8.6e-100], N[(1.0 / N[(N[(N[(z * y), $MachinePrecision] * z + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(z * N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.6 \cdot 10^{-100}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(z \cdot y, z, y\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(z, z \cdot \left(y \cdot x\right), y \cdot x\right)}\\
\end{array}
\end{array}
if y < 8.59999999999999997e-100Initial program 91.9%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f6496.2
Applied rewrites96.2%
lift-/.f64N/A
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft1-inN/A
lift-*.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-/r*N/A
*-commutativeN/A
lift-*.f64N/A
lift-/.f6491.5
Applied rewrites95.6%
if 8.59999999999999997e-100 < y Initial program 90.8%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6490.6
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6490.6
Applied rewrites90.6%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-inN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
distribute-rgt-inN/A
*-rgt-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
lift-fma.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
Applied rewrites98.7%
(FPCore (x y z) :precision binary64 (if (<= z 0.88) (/ (- 1.0 (* z z)) (* x y)) (/ 1.0 (* (* (* x y) z) z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.88) {
tmp = (1.0 - (z * z)) / (x * y);
} else {
tmp = 1.0 / (((x * y) * z) * z);
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= 0.88d0) then
tmp = (1.0d0 - (z * z)) / (x * y)
else
tmp = 1.0d0 / (((x * y) * z) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 0.88) {
tmp = (1.0 - (z * z)) / (x * y);
} else {
tmp = 1.0 / (((x * y) * z) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 0.88: tmp = (1.0 - (z * z)) / (x * y) else: tmp = 1.0 / (((x * y) * z) * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 0.88) tmp = Float64(Float64(1.0 - Float64(z * z)) / Float64(x * y)); else tmp = Float64(1.0 / Float64(Float64(Float64(x * y) * z) * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 0.88) tmp = (1.0 - (z * z)) / (x * y); else tmp = 1.0 / (((x * y) * z) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 0.88], N[(N[(1.0 - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(x * y), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.88:\\
\;\;\;\;\frac{1 - z \cdot z}{x \cdot y}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(x \cdot y\right) \cdot z\right) \cdot z}\\
\end{array}
\end{array}
if z < 0.880000000000000004Initial program 95.5%
Taylor expanded in z around inf
unpow2N/A
lower-*.f6436.8
Applied rewrites36.8%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6442.3
Applied rewrites42.3%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6442.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6442.3
Applied rewrites42.3%
Taylor expanded in z around 0
mul-1-negN/A
unpow2N/A
distribute-lft-neg-inN/A
fp-cancel-sub-sign-invN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f6472.3
Applied rewrites72.3%
if 0.880000000000000004 < z Initial program 79.3%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6479.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6479.0
Applied rewrites79.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-inN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
distribute-rgt-inN/A
*-rgt-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
lift-fma.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites93.9%
Taylor expanded in z around inf
associate-*r*N/A
distribute-rgt-outN/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
unpow2N/A
*-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites92.1%
(FPCore (x y z) :precision binary64 (if (<= z 0.88) (/ (- 1.0 (* z z)) (* x y)) (/ 1.0 (* (* (* z z) y) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.88) {
tmp = (1.0 - (z * z)) / (x * y);
} else {
tmp = 1.0 / (((z * z) * y) * x);
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= 0.88d0) then
tmp = (1.0d0 - (z * z)) / (x * y)
else
tmp = 1.0d0 / (((z * z) * y) * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 0.88) {
tmp = (1.0 - (z * z)) / (x * y);
} else {
tmp = 1.0 / (((z * z) * y) * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 0.88: tmp = (1.0 - (z * z)) / (x * y) else: tmp = 1.0 / (((z * z) * y) * x) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 0.88) tmp = Float64(Float64(1.0 - Float64(z * z)) / Float64(x * y)); else tmp = Float64(1.0 / Float64(Float64(Float64(z * z) * y) * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 0.88) tmp = (1.0 - (z * z)) / (x * y); else tmp = 1.0 / (((z * z) * y) * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 0.88], N[(N[(1.0 - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(x * y), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(z * z), $MachinePrecision] * y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.88:\\
\;\;\;\;\frac{1 - z \cdot z}{x \cdot y}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(z \cdot z\right) \cdot y\right) \cdot x}\\
\end{array}
\end{array}
if z < 0.880000000000000004Initial program 95.5%
Taylor expanded in z around inf
unpow2N/A
lower-*.f6436.8
Applied rewrites36.8%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6442.3
Applied rewrites42.3%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6442.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6442.3
Applied rewrites42.3%
Taylor expanded in z around 0
mul-1-negN/A
unpow2N/A
distribute-lft-neg-inN/A
fp-cancel-sub-sign-invN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f6472.3
Applied rewrites72.3%
if 0.880000000000000004 < z Initial program 79.3%
Taylor expanded in z around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6479.0
Applied rewrites79.0%
(FPCore (x y z) :precision binary64 (/ 1.0 (fma (* z y) (* z x) (* y x))))
double code(double x, double y, double z) {
return 1.0 / fma((z * y), (z * x), (y * x));
}
function code(x, y, z) return Float64(1.0 / fma(Float64(z * y), Float64(z * x), Float64(y * x))) end
code[x_, y_, z_] := N[(1.0 / N[(N[(z * y), $MachinePrecision] * N[(z * x), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(z \cdot y, z \cdot x, y \cdot x\right)}
\end{array}
Initial program 91.5%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6491.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6491.2
Applied rewrites91.2%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-inN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
distribute-rgt-inN/A
*-rgt-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
lift-fma.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites97.4%
(FPCore (x y z) :precision binary64 (/ 1.0 (fma (* x (* z y)) z (* y x))))
double code(double x, double y, double z) {
return 1.0 / fma((x * (z * y)), z, (y * x));
}
function code(x, y, z) return Float64(1.0 / fma(Float64(x * Float64(z * y)), z, Float64(y * x))) end
code[x_, y_, z_] := N[(1.0 / N[(N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision] * z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(x \cdot \left(z \cdot y\right), z, y \cdot x\right)}
\end{array}
Initial program 91.5%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6491.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6491.2
Applied rewrites91.2%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-inN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
distribute-rgt-inN/A
*-rgt-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
lift-fma.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites97.0%
(FPCore (x y z) :precision binary64 (/ 1.0 (* y x)))
double code(double x, double y, double z) {
return 1.0 / (y * x);
}
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 / (y * x)
end function
public static double code(double x, double y, double z) {
return 1.0 / (y * x);
}
def code(x, y, z): return 1.0 / (y * x)
function code(x, y, z) return Float64(1.0 / Float64(y * x)) end
function tmp = code(x, y, z) tmp = 1.0 / (y * x); end
code[x_, y_, z_] := N[(1.0 / N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{y \cdot x}
\end{array}
Initial program 91.5%
Taylor expanded in z around 0
Applied rewrites59.9%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6460.0
Applied rewrites60.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (* z z))) (t_1 (* y t_0)) (t_2 (/ (/ 1.0 y) (* t_0 x))))
(if (< t_1 (- INFINITY))
t_2
(if (< t_1 8.680743250567252e+305) (/ (/ 1.0 x) (* t_0 y)) t_2))))
double code(double x, double y, double z) {
double t_0 = 1.0 + (z * z);
double t_1 = y * t_0;
double t_2 = (1.0 / y) / (t_0 * x);
double tmp;
if (t_1 < -((double) INFINITY)) {
tmp = t_2;
} else if (t_1 < 8.680743250567252e+305) {
tmp = (1.0 / x) / (t_0 * y);
} else {
tmp = t_2;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = 1.0 + (z * z);
double t_1 = y * t_0;
double t_2 = (1.0 / y) / (t_0 * x);
double tmp;
if (t_1 < -Double.POSITIVE_INFINITY) {
tmp = t_2;
} else if (t_1 < 8.680743250567252e+305) {
tmp = (1.0 / x) / (t_0 * y);
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + (z * z) t_1 = y * t_0 t_2 = (1.0 / y) / (t_0 * x) tmp = 0 if t_1 < -math.inf: tmp = t_2 elif t_1 < 8.680743250567252e+305: tmp = (1.0 / x) / (t_0 * y) else: tmp = t_2 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(z * z)) t_1 = Float64(y * t_0) t_2 = Float64(Float64(1.0 / y) / Float64(t_0 * x)) tmp = 0.0 if (t_1 < Float64(-Inf)) tmp = t_2; elseif (t_1 < 8.680743250567252e+305) tmp = Float64(Float64(1.0 / x) / Float64(t_0 * y)); else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + (z * z); t_1 = y * t_0; t_2 = (1.0 / y) / (t_0 * x); tmp = 0.0; if (t_1 < -Inf) tmp = t_2; elseif (t_1 < 8.680743250567252e+305) tmp = (1.0 / x) / (t_0 * y); else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(1.0 / y), $MachinePrecision] / N[(t$95$0 * x), $MachinePrecision]), $MachinePrecision]}, If[Less[t$95$1, (-Infinity)], t$95$2, If[Less[t$95$1, 8.680743250567252e+305], N[(N[(1.0 / x), $MachinePrecision] / N[(t$95$0 * y), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + z \cdot z\\
t_1 := y \cdot t\_0\\
t_2 := \frac{\frac{1}{y}}{t\_0 \cdot x}\\
\mathbf{if}\;t\_1 < -\infty:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 < 8.680743250567252 \cdot 10^{+305}:\\
\;\;\;\;\frac{\frac{1}{x}}{t\_0 \cdot y}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
herbie shell --seed 2025026
(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)))))