
(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}
Sampling outcomes in binary64 precision:
Herbie found 6 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}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (* y z))))
(if (<= t_0 (- INFINITY))
(* (- y) (* z x))
(if (<= t_0 5e+193) (* x t_0) (* (- z) (* y x))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = -y * (z * x);
} else if (t_0 <= 5e+193) {
tmp = x * t_0;
} else {
tmp = -z * (y * x);
}
return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = -y * (z * x);
} else if (t_0 <= 5e+193) {
tmp = x * t_0;
} else {
tmp = -z * (y * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (y * z) tmp = 0 if t_0 <= -math.inf: tmp = -y * (z * x) elif t_0 <= 5e+193: tmp = x * t_0 else: tmp = -z * (y * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(Float64(-y) * Float64(z * x)); elseif (t_0 <= 5e+193) tmp = Float64(x * t_0); else tmp = Float64(Float64(-z) * Float64(y * x)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 1.0 - (y * z);
tmp = 0.0;
if (t_0 <= -Inf)
tmp = -y * (z * x);
elseif (t_0 <= 5e+193)
tmp = x * t_0;
else
tmp = -z * (y * x);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[((-y) * N[(z * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+193], N[(x * t$95$0), $MachinePrecision], N[((-z) * N[(y * x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\left(-y\right) \cdot \left(z \cdot x\right)\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+193}:\\
\;\;\;\;x \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -inf.0Initial program 58.9%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6499.7
Applied rewrites99.7%
Applied rewrites0.0%
Taylor expanded in y around inf
mul-1-negN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in x around 0
Applied rewrites99.7%
if -inf.0 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 4.99999999999999972e193Initial program 99.9%
if 4.99999999999999972e193 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 72.3%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
Applied rewrites7.4%
Taylor expanded in y around inf
mul-1-negN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (* y z))))
(if (<= t_0 -500.0)
(* (- y) (* z x))
(if (<= t_0 2.0)
(* x 1.0)
(if (<= t_0 5e+193) (* x (* (- y) z)) (* (- z) (* y x)))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if (t_0 <= -500.0) {
tmp = -y * (z * x);
} else if (t_0 <= 2.0) {
tmp = x * 1.0;
} else if (t_0 <= 5e+193) {
tmp = x * (-y * z);
} else {
tmp = -z * (y * x);
}
return tmp;
}
NOTE: x, 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, 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 <= (-500.0d0)) then
tmp = -y * (z * x)
else if (t_0 <= 2.0d0) then
tmp = x * 1.0d0
else if (t_0 <= 5d+193) then
tmp = x * (-y * z)
else
tmp = -z * (y * x)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if (t_0 <= -500.0) {
tmp = -y * (z * x);
} else if (t_0 <= 2.0) {
tmp = x * 1.0;
} else if (t_0 <= 5e+193) {
tmp = x * (-y * z);
} else {
tmp = -z * (y * x);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (y * z) tmp = 0 if t_0 <= -500.0: tmp = -y * (z * x) elif t_0 <= 2.0: tmp = x * 1.0 elif t_0 <= 5e+193: tmp = x * (-y * z) else: tmp = -z * (y * x) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if (t_0 <= -500.0) tmp = Float64(Float64(-y) * Float64(z * x)); elseif (t_0 <= 2.0) tmp = Float64(x * 1.0); elseif (t_0 <= 5e+193) tmp = Float64(x * Float64(Float64(-y) * z)); else tmp = Float64(Float64(-z) * Float64(y * x)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 1.0 - (y * z);
tmp = 0.0;
if (t_0 <= -500.0)
tmp = -y * (z * x);
elseif (t_0 <= 2.0)
tmp = x * 1.0;
elseif (t_0 <= 5e+193)
tmp = x * (-y * z);
else
tmp = -z * (y * x);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -500.0], N[((-y) * N[(z * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(x * 1.0), $MachinePrecision], If[LessEqual[t$95$0, 5e+193], N[(x * N[((-y) * z), $MachinePrecision]), $MachinePrecision], N[((-z) * N[(y * x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -500:\\
\;\;\;\;\left(-y\right) \cdot \left(z \cdot x\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;x \cdot 1\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+193}:\\
\;\;\;\;x \cdot \left(\left(-y\right) \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -500Initial program 87.1%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6493.4
Applied rewrites93.4%
Applied rewrites38.3%
Taylor expanded in y around inf
mul-1-negN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6485.2
Applied rewrites85.2%
Taylor expanded in x around 0
Applied rewrites89.3%
if -500 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites97.6%
if 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 4.99999999999999972e193Initial program 99.6%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6493.8
Applied rewrites93.8%
if 4.99999999999999972e193 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 72.3%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
Applied rewrites7.4%
Taylor expanded in y around inf
mul-1-negN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (* y z)))) (if (or (<= t_0 -500.0) (not (<= t_0 400.0))) (* (- y) (* z x)) (* x 1.0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -500.0) || !(t_0 <= 400.0)) {
tmp = -y * (z * x);
} else {
tmp = x * 1.0;
}
return tmp;
}
NOTE: x, 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, 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 <= (-500.0d0)) .or. (.not. (t_0 <= 400.0d0))) then
tmp = -y * (z * x)
else
tmp = x * 1.0d0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -500.0) || !(t_0 <= 400.0)) {
tmp = -y * (z * x);
} else {
tmp = x * 1.0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (y * z) tmp = 0 if (t_0 <= -500.0) or not (t_0 <= 400.0): tmp = -y * (z * x) else: tmp = x * 1.0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if ((t_0 <= -500.0) || !(t_0 <= 400.0)) tmp = Float64(Float64(-y) * Float64(z * x)); else tmp = Float64(x * 1.0); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = 1.0 - (y * z);
tmp = 0.0;
if ((t_0 <= -500.0) || ~((t_0 <= 400.0)))
tmp = -y * (z * x);
else
tmp = x * 1.0;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -500.0], N[Not[LessEqual[t$95$0, 400.0]], $MachinePrecision]], N[((-y) * N[(z * x), $MachinePrecision]), $MachinePrecision], N[(x * 1.0), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -500 \lor \neg \left(t\_0 \leq 400\right):\\
\;\;\;\;\left(-y\right) \cdot \left(z \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -500 or 400 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 87.3%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6492.4
Applied rewrites92.4%
Applied rewrites34.1%
Taylor expanded in y around inf
mul-1-negN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6485.2
Applied rewrites85.2%
Taylor expanded in x around 0
Applied rewrites90.1%
if -500 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 400Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites97.0%
Final simplification93.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 1e-38) (fma (* x z) (- y) x) (fma (* (- y) z) x x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 1e-38) {
tmp = fma((x * z), -y, x);
} else {
tmp = fma((-y * z), x, x);
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 1e-38) tmp = fma(Float64(x * z), Float64(-y), x); else tmp = fma(Float64(Float64(-y) * z), x, x); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[x, 1e-38], N[(N[(x * z), $MachinePrecision] * (-y) + x), $MachinePrecision], N[(N[((-y) * z), $MachinePrecision] * x + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{-38}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot z, -y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(-y\right) \cdot z, x, x\right)\\
\end{array}
\end{array}
if x < 9.9999999999999996e-39Initial program 91.8%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6495.9
Applied rewrites95.9%
if 9.9999999999999996e-39 < x Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 1e-38) (fma (* x z) (- y) x) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 1e-38) {
tmp = fma((x * z), -y, x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 1e-38) tmp = fma(Float64(x * z), Float64(-y), x); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[x, 1e-38], N[(N[(x * z), $MachinePrecision] * (-y) + x), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{-38}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot z, -y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if x < 9.9999999999999996e-39Initial program 91.8%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6495.9
Applied rewrites95.9%
if 9.9999999999999996e-39 < x Initial program 100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x 1.0))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x * 1.0;
}
NOTE: x, 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, 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
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x * 1.0;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x * 1.0
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x * 1.0) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x * 1.0;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot 1
\end{array}
Initial program 94.1%
Taylor expanded in y around 0
Applied rewrites53.6%
herbie shell --seed 2024363
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))