
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (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 = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (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 = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
(FPCore (x y z) :precision binary64 (if (<= (- 1.0 (* y z)) 1e+183) (- x (* (* z y) x)) (* (* (- x) y) z)))
double code(double x, double y, double z) {
double tmp;
if ((1.0 - (y * z)) <= 1e+183) {
tmp = x - ((z * y) * x);
} else {
tmp = (-x * y) * 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 ((1.0d0 - (y * z)) <= 1d+183) then
tmp = x - ((z * y) * x)
else
tmp = (-x * y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((1.0 - (y * z)) <= 1e+183) {
tmp = x - ((z * y) * x);
} else {
tmp = (-x * y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (1.0 - (y * z)) <= 1e+183: tmp = x - ((z * y) * x) else: tmp = (-x * y) * z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(1.0 - Float64(y * z)) <= 1e+183) tmp = Float64(x - Float64(Float64(z * y) * x)); else tmp = Float64(Float64(Float64(-x) * y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((1.0 - (y * z)) <= 1e+183) tmp = x - ((z * y) * x); else tmp = (-x * y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision], 1e+183], N[(x - N[(N[(z * y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - y \cdot z \leq 10^{+183}:\\
\;\;\;\;x - \left(z \cdot y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-x\right) \cdot y\right) \cdot z\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 9.99999999999999947e182Initial program 97.6%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6497.6
Applied rewrites97.6%
if 9.99999999999999947e182 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 83.4%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6498.6
Applied rewrites98.6%
Taylor expanded in y around inf
lift-neg.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
mul-1-negN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
associate-*l*N/A
Applied rewrites98.5%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-neg.f64N/A
mul-1-negN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*r*N/A
mul-1-negN/A
lift-neg.f64N/A
lower-*.f6498.6
Applied rewrites98.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (* y z))))
(if (<= t_0 -2000000000.0)
(* x (* (- y) z))
(if (<= t_0 2.0) (/ x (fma z y 1.0)) (* (* (- x) y) z)))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if (t_0 <= -2000000000.0) {
tmp = x * (-y * z);
} else if (t_0 <= 2.0) {
tmp = x / fma(z, y, 1.0);
} else {
tmp = (-x * y) * z;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if (t_0 <= -2000000000.0) tmp = Float64(x * Float64(Float64(-y) * z)); elseif (t_0 <= 2.0) tmp = Float64(x / fma(z, y, 1.0)); else tmp = Float64(Float64(Float64(-x) * y) * z); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2000000000.0], N[(x * N[((-y) * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(x / N[(z * y + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -2000000000:\\
\;\;\;\;x \cdot \left(\left(-y\right) \cdot z\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(z, y, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-x\right) \cdot y\right) \cdot z\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -2e9Initial program 91.4%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6491.0
Applied rewrites91.0%
if -2e9 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
flip--N/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites97.4%
if 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 91.9%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6491.8
Applied rewrites91.8%
Taylor expanded in y around inf
lift-neg.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
mul-1-negN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
associate-*l*N/A
Applied rewrites90.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-neg.f64N/A
mul-1-negN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*r*N/A
mul-1-negN/A
lift-neg.f64N/A
lower-*.f6490.2
Applied rewrites90.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (* y z))))
(if (<= t_0 -2000000000.0)
(* x (* (- y) z))
(if (<= t_0 2.0) x (* (* (- x) y) z)))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if (t_0 <= -2000000000.0) {
tmp = x * (-y * z);
} else if (t_0 <= 2.0) {
tmp = x;
} else {
tmp = (-x * y) * 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) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - (y * z)
if (t_0 <= (-2000000000.0d0)) then
tmp = x * (-y * z)
else if (t_0 <= 2.0d0) then
tmp = x
else
tmp = (-x * y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if (t_0 <= -2000000000.0) {
tmp = x * (-y * z);
} else if (t_0 <= 2.0) {
tmp = x;
} else {
tmp = (-x * y) * z;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (y * z) tmp = 0 if t_0 <= -2000000000.0: tmp = x * (-y * z) elif t_0 <= 2.0: tmp = x else: tmp = (-x * y) * z return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if (t_0 <= -2000000000.0) tmp = Float64(x * Float64(Float64(-y) * z)); elseif (t_0 <= 2.0) tmp = x; else tmp = Float64(Float64(Float64(-x) * y) * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (y * z); tmp = 0.0; if (t_0 <= -2000000000.0) tmp = x * (-y * z); elseif (t_0 <= 2.0) tmp = x; else tmp = (-x * y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2000000000.0], N[(x * N[((-y) * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2.0], x, N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -2000000000:\\
\;\;\;\;x \cdot \left(\left(-y\right) \cdot z\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-x\right) \cdot y\right) \cdot z\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -2e9Initial program 91.4%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6491.0
Applied rewrites91.0%
if -2e9 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites96.3%
if 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 91.9%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6491.8
Applied rewrites91.8%
Taylor expanded in y around inf
lift-neg.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
mul-1-negN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
associate-*l*N/A
Applied rewrites90.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-neg.f64N/A
mul-1-negN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*r*N/A
mul-1-negN/A
lift-neg.f64N/A
lower-*.f6490.2
Applied rewrites90.2%
(FPCore (x y z) :precision binary64 (fma (* (- x) y) z (* x 1.0)))
double code(double x, double y, double z) {
return fma((-x * y), z, (x * 1.0));
}
function code(x, y, z) return fma(Float64(Float64(-x) * y), z, Float64(x * 1.0)) end
code[x_, y_, z_] := N[(N[((-x) * y), $MachinePrecision] * z + N[(x * 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(-x\right) \cdot y, z, x \cdot 1\right)
\end{array}
Initial program 95.9%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6494.2
Applied rewrites94.2%
(FPCore (x y z) :precision binary64 (- x (* (* y x) z)))
double code(double x, double y, double z) {
return x - ((y * x) * 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 = x - ((y * x) * z)
end function
public static double code(double x, double y, double z) {
return x - ((y * x) * z);
}
def code(x, y, z): return x - ((y * x) * z)
function code(x, y, z) return Float64(x - Float64(Float64(y * x) * z)) end
function tmp = code(x, y, z) tmp = x - ((y * x) * z); end
code[x_, y_, z_] := N[(x - N[(N[(y * x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(y \cdot x\right) \cdot z
\end{array}
Initial program 95.9%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6494.2
Applied rewrites94.2%
lift-*.f64N/A
lift-fma.f64N/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
mul-1-negN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
lower--.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6494.2
Applied rewrites94.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (* y z))) (t_1 (* (* (- x) y) z))) (if (<= t_0 -2000000000.0) t_1 (if (<= t_0 2.0) x t_1))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = (-x * y) * z;
double tmp;
if (t_0 <= -2000000000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (y * z)
t_1 = (-x * y) * z
if (t_0 <= (-2000000000.0d0)) then
tmp = t_1
else if (t_0 <= 2.0d0) then
tmp = x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = (-x * y) * z;
double tmp;
if (t_0 <= -2000000000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (y * z) t_1 = (-x * y) * z tmp = 0 if t_0 <= -2000000000.0: tmp = t_1 elif t_0 <= 2.0: tmp = x else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) t_1 = Float64(Float64(Float64(-x) * y) * z) tmp = 0.0 if (t_0 <= -2000000000.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = x; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (y * z); t_1 = (-x * y) * z; tmp = 0.0; if (t_0 <= -2000000000.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[t$95$0, -2000000000.0], t$95$1, If[LessEqual[t$95$0, 2.0], x, t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
t_1 := \left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{if}\;t\_0 \leq -2000000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -2e9 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 91.7%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6492.4
Applied rewrites92.4%
Taylor expanded in y around inf
lift-neg.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
mul-1-negN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
associate-*l*N/A
Applied rewrites90.9%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-neg.f64N/A
mul-1-negN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*r*N/A
mul-1-negN/A
lift-neg.f64N/A
lower-*.f6491.5
Applied rewrites91.5%
if -2e9 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites96.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (* y z))) (t_1 (* (* z (- x)) y))) (if (<= t_0 -2000000000.0) t_1 (if (<= t_0 2.0) x t_1))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = (z * -x) * y;
double tmp;
if (t_0 <= -2000000000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (y * z)
t_1 = (z * -x) * y
if (t_0 <= (-2000000000.0d0)) then
tmp = t_1
else if (t_0 <= 2.0d0) then
tmp = x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = (z * -x) * y;
double tmp;
if (t_0 <= -2000000000.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (y * z) t_1 = (z * -x) * y tmp = 0 if t_0 <= -2000000000.0: tmp = t_1 elif t_0 <= 2.0: tmp = x else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) t_1 = Float64(Float64(z * Float64(-x)) * y) tmp = 0.0 if (t_0 <= -2000000000.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = x; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (y * z); t_1 = (z * -x) * y; tmp = 0.0; if (t_0 <= -2000000000.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(z * (-x)), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -2000000000.0], t$95$1, If[LessEqual[t$95$0, 2.0], x, t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
t_1 := \left(z \cdot \left(-x\right)\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -2000000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -2e9 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 91.7%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6492.4
Applied rewrites92.4%
Taylor expanded in y around inf
lift-neg.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
mul-1-negN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
associate-*l*N/A
Applied rewrites90.9%
if -2e9 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites96.3%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return 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 = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 95.9%
Taylor expanded in y around 0
Applied rewrites51.0%
herbie shell --seed 2025115
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))