
(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 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 -1e+144)
(* (* (- x) y) z)
(if (<= t_0 2e+172) (* x (fma (- z) y 1.0)) (* (- y) (* z 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 <= -1e+144) {
tmp = (-x * y) * z;
} else if (t_0 <= 2e+172) {
tmp = x * fma(-z, y, 1.0);
} else {
tmp = -y * (z * 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 <= -1e+144) tmp = Float64(Float64(Float64(-x) * y) * z); elseif (t_0 <= 2e+172) tmp = Float64(x * fma(Float64(-z), y, 1.0)); else tmp = Float64(Float64(-y) * Float64(z * x)); end return 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, -1e+144], N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[t$95$0, 2e+172], N[(x * N[((-z) * y + 1.0), $MachinePrecision]), $MachinePrecision], N[((-y) * N[(z * 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 -1 \cdot 10^{+144}:\\
\;\;\;\;\left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+172}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(-z, y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot \left(z \cdot x\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -1.00000000000000002e144Initial program 86.9%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
lft-mult-inverseN/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
flip-+N/A
*-commutativeN/A
*-commutativeN/A
rgt-mult-inverseN/A
rgt-mult-inverseN/A
*-commutativeN/A
rgt-mult-inverseN/A
flip-+N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6486.9
Applied rewrites86.9%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
lift-*.f6497.9
Applied rewrites97.9%
if -1.00000000000000002e144 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2.0000000000000002e172Initial program 99.9%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
lft-mult-inverseN/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
flip-+N/A
*-commutativeN/A
*-commutativeN/A
rgt-mult-inverseN/A
rgt-mult-inverseN/A
*-commutativeN/A
rgt-mult-inverseN/A
flip-+N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
if 2.0000000000000002e172 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 86.6%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
lft-mult-inverseN/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
flip-+N/A
*-commutativeN/A
*-commutativeN/A
rgt-mult-inverseN/A
rgt-mult-inverseN/A
*-commutativeN/A
rgt-mult-inverseN/A
flip-+N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6486.6
Applied rewrites86.6%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
lift-*.f6498.5
Applied rewrites98.5%
+-commutative98.5
fp-cancel-sub-sign-inv98.5
*-commutative98.5
flip--98.5
metadata-eval98.5
*-commutative98.5
*-commutative98.5
associate-*l*98.5
*-commutative98.5
+-commutative98.5
associate-*r/98.5
*-commutative98.5
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lift-neg.f64N/A
mul-1-negN/A
associate-*r*N/A
Applied rewrites98.4%
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 -1e+144)
(* (* (- x) y) z)
(if (<= t_0 2e+172) (- x (* (* z y) x)) (* (- y) (* z 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 <= -1e+144) {
tmp = (-x * y) * z;
} else if (t_0 <= 2e+172) {
tmp = x - ((z * y) * x);
} else {
tmp = -y * (z * 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 <= (-1d+144)) then
tmp = (-x * y) * z
else if (t_0 <= 2d+172) then
tmp = x - ((z * y) * x)
else
tmp = -y * (z * 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 <= -1e+144) {
tmp = (-x * y) * z;
} else if (t_0 <= 2e+172) {
tmp = x - ((z * y) * x);
} else {
tmp = -y * (z * 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 <= -1e+144: tmp = (-x * y) * z elif t_0 <= 2e+172: tmp = x - ((z * y) * x) else: tmp = -y * (z * 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 <= -1e+144) tmp = Float64(Float64(Float64(-x) * y) * z); elseif (t_0 <= 2e+172) tmp = Float64(x - Float64(Float64(z * y) * x)); else tmp = Float64(Float64(-y) * Float64(z * 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 <= -1e+144)
tmp = (-x * y) * z;
elseif (t_0 <= 2e+172)
tmp = x - ((z * y) * x);
else
tmp = -y * (z * 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, -1e+144], N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[t$95$0, 2e+172], N[(x - N[(N[(z * y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[((-y) * N[(z * 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 -1 \cdot 10^{+144}:\\
\;\;\;\;\left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+172}:\\
\;\;\;\;x - \left(z \cdot y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot \left(z \cdot x\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -1.00000000000000002e144Initial program 86.9%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
lft-mult-inverseN/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
flip-+N/A
*-commutativeN/A
*-commutativeN/A
rgt-mult-inverseN/A
rgt-mult-inverseN/A
*-commutativeN/A
rgt-mult-inverseN/A
flip-+N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6486.9
Applied rewrites86.9%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
lift-*.f6497.9
Applied rewrites97.9%
if -1.00000000000000002e144 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2.0000000000000002e172Initial program 99.9%
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-*.f6499.9
Applied rewrites99.9%
if 2.0000000000000002e172 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 86.6%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
lft-mult-inverseN/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
flip-+N/A
*-commutativeN/A
*-commutativeN/A
rgt-mult-inverseN/A
rgt-mult-inverseN/A
*-commutativeN/A
rgt-mult-inverseN/A
flip-+N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6486.6
Applied rewrites86.6%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
lift-*.f6498.5
Applied rewrites98.5%
+-commutative98.5
fp-cancel-sub-sign-inv98.5
*-commutative98.5
flip--98.5
metadata-eval98.5
*-commutative98.5
*-commutative98.5
associate-*l*98.5
*-commutative98.5
+-commutative98.5
associate-*r/98.5
*-commutative98.5
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lift-neg.f64N/A
mul-1-negN/A
associate-*r*N/A
Applied rewrites98.4%
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 0.999931908059773)
(- x (* (* z x) y))
(if (<= t_0 2.0) (/ x (fma z y 1.0)) (* (* (- x) y) z)))))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 <= 0.999931908059773) {
tmp = x - ((z * x) * y);
} else if (t_0 <= 2.0) {
tmp = x / fma(z, y, 1.0);
} else {
tmp = (-x * y) * z;
}
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 <= 0.999931908059773) tmp = Float64(x - Float64(Float64(z * x) * y)); 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
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, 0.999931908059773], N[(x - N[(N[(z * x), $MachinePrecision] * y), $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}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq 0.999931908059773:\\
\;\;\;\;x - \left(z \cdot x\right) \cdot y\\
\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)) < 0.999931908059772945Initial program 92.0%
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-*.f6492.0
Applied rewrites92.0%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6492.6
Applied rewrites92.6%
if 0.999931908059772945 < (-.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 rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.5%
if 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 92.7%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
lft-mult-inverseN/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
flip-+N/A
*-commutativeN/A
*-commutativeN/A
rgt-mult-inverseN/A
rgt-mult-inverseN/A
*-commutativeN/A
rgt-mult-inverseN/A
flip-+N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6492.7
Applied rewrites92.7%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
lift-*.f6490.6
Applied rewrites90.6%
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))) (t_1 (* (* (- x) y) z))) (if (<= t_0 -1.0) t_1 (if (<= t_0 2.0) (/ x (fma z y 1.0)) t_1))))
assert(x < y && y < z);
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 <= -1.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x / fma(z, y, 1.0);
} else {
tmp = t_1;
}
return tmp;
}
x, y, z = sort([x, y, z]) 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 <= -1.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = Float64(x / fma(z, y, 1.0)); else tmp = t_1; end return 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]}, Block[{t$95$1 = N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[t$95$0, -1.0], t$95$1, If[LessEqual[t$95$0, 2.0], N[(x / N[(z * y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\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 -1:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(z, y, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -1 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 92.3%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
lft-mult-inverseN/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
flip-+N/A
*-commutativeN/A
*-commutativeN/A
rgt-mult-inverseN/A
rgt-mult-inverseN/A
*-commutativeN/A
rgt-mult-inverseN/A
flip-+N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6492.3
Applied rewrites92.3%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
lift-*.f6490.6
Applied rewrites90.6%
if -1 < (-.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 rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.2%
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))) (t_1 (* (* (- x) y) z))) (if (<= t_0 -1.0) t_1 (if (<= t_0 2.0) x t_1))))
assert(x < y && y < z);
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 <= -1.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (y * z)
t_1 = (-x * y) * z
if (t_0 <= (-1.0d0)) then
tmp = t_1
else if (t_0 <= 2.0d0) then
tmp = x
else
tmp = t_1
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 t_1 = (-x * y) * z;
double tmp;
if (t_0 <= -1.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x;
} else {
tmp = t_1;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = 1.0 - (y * z) t_1 = (-x * y) * z tmp = 0 if t_0 <= -1.0: tmp = t_1 elif t_0 <= 2.0: tmp = x else: tmp = t_1 return tmp
x, y, z = sort([x, y, z]) 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 <= -1.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = x; else tmp = t_1; 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);
t_1 = (-x * y) * z;
tmp = 0.0;
if (t_0 <= -1.0)
tmp = t_1;
elseif (t_0 <= 2.0)
tmp = x;
else
tmp = t_1;
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]}, Block[{t$95$1 = N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[t$95$0, -1.0], t$95$1, If[LessEqual[t$95$0, 2.0], x, t$95$1]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\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 -1:\\
\;\;\;\;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)) < -1 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 92.3%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
lft-mult-inverseN/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
flip-+N/A
*-commutativeN/A
*-commutativeN/A
rgt-mult-inverseN/A
rgt-mult-inverseN/A
*-commutativeN/A
rgt-mult-inverseN/A
flip-+N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6492.3
Applied rewrites92.3%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
lift-*.f6490.6
Applied rewrites90.6%
if -1 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites98.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(x < y && y < z);
double code(double x, double y, double z) {
return x;
}
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
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x
x, y, z = sort([x, y, z]) function code(x, y, z) return x end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x
\end{array}
Initial program 96.1%
Taylor expanded in y around 0
Applied rewrites50.4%
herbie shell --seed 2025117
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))