
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
double code(double x, double y, double z) {
return x * (1.0 - ((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 - ((1.0d0 - y) * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * z));
}
def code(x, y, z): return x * (1.0 - ((1.0 - y) * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - ((1.0 - y) * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
double code(double x, double y, double z) {
return x * (1.0 - ((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 - ((1.0d0 - y) * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * z));
}
def code(x, y, z): return x * (1.0 - ((1.0 - y) * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - ((1.0 - y) * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (* z x) (- y 1.0) x))
double code(double x, double y, double z) {
return fma((z * x), (y - 1.0), x);
}
function code(x, y, z) return fma(Float64(z * x), Float64(y - 1.0), x) end
code[x_, y_, z_] := N[(N[(z * x), $MachinePrecision] * N[(y - 1.0), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z \cdot x, y - 1, x\right)
\end{array}
Initial program 98.4%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lower-neg.f6498.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
lift-fma.f64N/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
associate-*r*N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6498.5
Applied rewrites98.5%
Taylor expanded in y around 0
lower--.f6498.5
Applied rewrites98.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (* (- 1.0 y) z))))
(if (or (<= t_0 -1.0) (not (<= t_0 200000000.0)))
(* (* (- y 1.0) x) z)
(fma (- x) z x))))
double code(double x, double y, double z) {
double t_0 = 1.0 - ((1.0 - y) * z);
double tmp;
if ((t_0 <= -1.0) || !(t_0 <= 200000000.0)) {
tmp = ((y - 1.0) * x) * z;
} else {
tmp = fma(-x, z, x);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(1.0 - Float64(Float64(1.0 - y) * z)) tmp = 0.0 if ((t_0 <= -1.0) || !(t_0 <= 200000000.0)) tmp = Float64(Float64(Float64(y - 1.0) * x) * z); else tmp = fma(Float64(-x), z, x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1.0], N[Not[LessEqual[t$95$0, 200000000.0]], $MachinePrecision]], N[(N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision] * z), $MachinePrecision], N[((-x) * z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \left(1 - y\right) \cdot z\\
\mathbf{if}\;t\_0 \leq -1 \lor \neg \left(t\_0 \leq 200000000\right):\\
\;\;\;\;\left(\left(y - 1\right) \cdot x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < -1 or 2e8 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) Initial program 97.3%
Taylor expanded in z around inf
Applied rewrites96.9%
Applied rewrites94.4%
if -1 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < 2e8Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lower-neg.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites95.4%
Taylor expanded in y around 0
Applied rewrites97.8%
Final simplification95.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (* (- 1.0 y) z))))
(if (<= t_0 -1.0)
(* (* (- y 1.0) x) z)
(if (<= t_0 2.0) (fma (- x) z x) (* (- y 1.0) (* x z))))))
double code(double x, double y, double z) {
double t_0 = 1.0 - ((1.0 - y) * z);
double tmp;
if (t_0 <= -1.0) {
tmp = ((y - 1.0) * x) * z;
} else if (t_0 <= 2.0) {
tmp = fma(-x, z, x);
} else {
tmp = (y - 1.0) * (x * z);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(1.0 - Float64(Float64(1.0 - y) * z)) tmp = 0.0 if (t_0 <= -1.0) tmp = Float64(Float64(Float64(y - 1.0) * x) * z); elseif (t_0 <= 2.0) tmp = fma(Float64(-x), z, x); else tmp = Float64(Float64(y - 1.0) * Float64(x * z)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1.0], N[(N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[((-x) * z + x), $MachinePrecision], N[(N[(y - 1.0), $MachinePrecision] * N[(x * z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \left(1 - y\right) \cdot z\\
\mathbf{if}\;t\_0 \leq -1:\\
\;\;\;\;\left(\left(y - 1\right) \cdot x\right) \cdot z\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y - 1\right) \cdot \left(x \cdot z\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < -1Initial program 97.4%
Taylor expanded in z around inf
Applied rewrites95.6%
Applied rewrites96.5%
if -1 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < 2Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lower-neg.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites96.2%
Taylor expanded in y around 0
Applied rewrites99.3%
if 2 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) Initial program 97.3%
Taylor expanded in z around inf
Applied rewrites96.4%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (<= (- 1.0 (* (- 1.0 y) z)) 1e+15) (fma (* (- y 1.0) x) z x) (* (- y 1.0) (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((1.0 - ((1.0 - y) * z)) <= 1e+15) {
tmp = fma(((y - 1.0) * x), z, x);
} else {
tmp = (y - 1.0) * (x * z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(1.0 - Float64(Float64(1.0 - y) * z)) <= 1e+15) tmp = fma(Float64(Float64(y - 1.0) * x), z, x); else tmp = Float64(Float64(y - 1.0) * Float64(x * z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], 1e+15], N[(N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(y - 1.0), $MachinePrecision] * N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - \left(1 - y\right) \cdot z \leq 10^{+15}:\\
\;\;\;\;\mathsf{fma}\left(\left(y - 1\right) \cdot x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y - 1\right) \cdot \left(x \cdot z\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) < 1e15Initial program 98.9%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lower-neg.f6498.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.9
Applied rewrites98.9%
Taylor expanded in x around 0
Applied rewrites96.8%
if 1e15 < (-.f64 #s(literal 1 binary64) (*.f64 (-.f64 #s(literal 1 binary64) y) z)) Initial program 97.2%
Taylor expanded in z around inf
Applied rewrites98.5%
Final simplification97.3%
(FPCore (x y z) :precision binary64 (if (or (<= (- 1.0 y) -500000000.0) (not (<= (- 1.0 y) 1.000001))) (fma (* x y) z x) (fma (- x) z x)))
double code(double x, double y, double z) {
double tmp;
if (((1.0 - y) <= -500000000.0) || !((1.0 - y) <= 1.000001)) {
tmp = fma((x * y), z, x);
} else {
tmp = fma(-x, z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((Float64(1.0 - y) <= -500000000.0) || !(Float64(1.0 - y) <= 1.000001)) tmp = fma(Float64(x * y), z, x); else tmp = fma(Float64(-x), z, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[N[(1.0 - y), $MachinePrecision], -500000000.0], N[Not[LessEqual[N[(1.0 - y), $MachinePrecision], 1.000001]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] * z + x), $MachinePrecision], N[((-x) * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - y \leq -500000000 \lor \neg \left(1 - y \leq 1.000001\right):\\
\;\;\;\;\mathsf{fma}\left(x \cdot y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) y) < -5e8 or 1.00000099999999992 < (-.f64 #s(literal 1 binary64) y) Initial program 97.1%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lower-neg.f6497.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6497.0
Applied rewrites97.0%
Taylor expanded in x around 0
Applied rewrites91.5%
Taylor expanded in y around inf
Applied rewrites91.3%
if -5e8 < (-.f64 #s(literal 1 binary64) y) < 1.00000099999999992Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lower-neg.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites98.3%
Final simplification94.6%
(FPCore (x y z) :precision binary64 (if (<= (- 1.0 y) -5e+58) (* x (* z y)) (if (<= (- 1.0 y) 1e+25) (fma (- x) z x) (* (* x z) y))))
double code(double x, double y, double z) {
double tmp;
if ((1.0 - y) <= -5e+58) {
tmp = x * (z * y);
} else if ((1.0 - y) <= 1e+25) {
tmp = fma(-x, z, x);
} else {
tmp = (x * z) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(1.0 - y) <= -5e+58) tmp = Float64(x * Float64(z * y)); elseif (Float64(1.0 - y) <= 1e+25) tmp = fma(Float64(-x), z, x); else tmp = Float64(Float64(x * z) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(1.0 - y), $MachinePrecision], -5e+58], N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 - y), $MachinePrecision], 1e+25], N[((-x) * z + x), $MachinePrecision], N[(N[(x * z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - y \leq -5 \cdot 10^{+58}:\\
\;\;\;\;x \cdot \left(z \cdot y\right)\\
\mathbf{elif}\;1 - y \leq 10^{+25}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot z\right) \cdot y\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) y) < -4.99999999999999986e58Initial program 96.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6478.0
Applied rewrites78.0%
if -4.99999999999999986e58 < (-.f64 #s(literal 1 binary64) y) < 1.00000000000000009e25Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lower-neg.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites94.9%
if 1.00000000000000009e25 < (-.f64 #s(literal 1 binary64) y) Initial program 96.7%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lower-neg.f6496.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6496.6
Applied rewrites96.6%
lift-fma.f64N/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
associate-*r*N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6497.4
Applied rewrites97.4%
Taylor expanded in y around 0
lower--.f6497.4
Applied rewrites97.4%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6477.7
Applied rewrites77.7%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.2e+30) (not (<= y 1.75e+55))) (* (* x z) y) (fma (- x) z x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.2e+30) || !(y <= 1.75e+55)) {
tmp = (x * z) * y;
} else {
tmp = fma(-x, z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -1.2e+30) || !(y <= 1.75e+55)) tmp = Float64(Float64(x * z) * y); else tmp = fma(Float64(-x), z, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.2e+30], N[Not[LessEqual[y, 1.75e+55]], $MachinePrecision]], N[(N[(x * z), $MachinePrecision] * y), $MachinePrecision], N[((-x) * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+30} \lor \neg \left(y \leq 1.75 \cdot 10^{+55}\right):\\
\;\;\;\;\left(x \cdot z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\end{array}
\end{array}
if y < -1.2e30 or 1.75000000000000005e55 < y Initial program 96.4%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lower-neg.f6496.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6496.4
Applied rewrites96.4%
lift-fma.f64N/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
associate-*r*N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6496.6
Applied rewrites96.6%
Taylor expanded in y around 0
lower--.f6496.6
Applied rewrites96.6%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6477.8
Applied rewrites77.8%
if -1.2e30 < y < 1.75000000000000005e55Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lower-neg.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites94.9%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* (- x) z) (* x 1.0)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = -x * z;
} else {
tmp = x * 1.0;
}
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 <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = -x * z
else
tmp = x * 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = -x * z;
} else {
tmp = x * 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = -x * z else: tmp = x * 1.0 return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) tmp = Float64(Float64(-x) * z); else tmp = Float64(x * 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 1.0))) tmp = -x * z; else tmp = x * 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[((-x) * z), $MachinePrecision], N[(x * 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;\left(-x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 96.6%
Taylor expanded in z around inf
Applied rewrites98.7%
Taylor expanded in y around 0
Applied rewrites55.7%
if -1 < z < 1Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lft-mult-inverseN/A
distribute-rgt-outN/A
*-rgt-identityN/A
distribute-lft-out--N/A
associate--l+N/A
distribute-rgt-inN/A
fp-cancel-sign-sub-invN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
Applied rewrites99.9%
Taylor expanded in z around 0
Applied rewrites71.0%
Final simplification64.3%
(FPCore (x y z) :precision binary64 (* x (fma z y (- 1.0 z))))
double code(double x, double y, double z) {
return x * fma(z, y, (1.0 - z));
}
function code(x, y, z) return Float64(x * fma(z, y, Float64(1.0 - z))) end
code[x_, y_, z_] := N[(x * N[(z * y + N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(z, y, 1 - z\right)
\end{array}
Initial program 98.4%
Taylor expanded in y around 0
+-commutativeN/A
lft-mult-inverseN/A
distribute-rgt-outN/A
*-rgt-identityN/A
distribute-lft-out--N/A
associate--l+N/A
distribute-rgt-inN/A
fp-cancel-sign-sub-invN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
Applied rewrites98.4%
(FPCore (x y z) :precision binary64 (fma (- x) z x))
double code(double x, double y, double z) {
return fma(-x, z, x);
}
function code(x, y, z) return fma(Float64(-x), z, x) end
code[x_, y_, z_] := N[((-x) * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-x, z, x\right)
\end{array}
Initial program 98.4%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lower-neg.f6498.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
Taylor expanded in x around 0
Applied rewrites95.5%
Taylor expanded in y around 0
Applied rewrites65.8%
Final simplification65.8%
(FPCore (x y z) :precision binary64 (* x 1.0))
double code(double x, double y, double z) {
return x * 1.0;
}
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
public static double code(double x, double y, double z) {
return x * 1.0;
}
def code(x, y, z): return x * 1.0
function code(x, y, z) return Float64(x * 1.0) end
function tmp = code(x, y, z) tmp = x * 1.0; end
code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 1
\end{array}
Initial program 98.4%
Taylor expanded in y around 0
+-commutativeN/A
lft-mult-inverseN/A
distribute-rgt-outN/A
*-rgt-identityN/A
distribute-lft-out--N/A
associate--l+N/A
distribute-rgt-inN/A
fp-cancel-sign-sub-invN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
Applied rewrites98.4%
Taylor expanded in z around 0
Applied rewrites41.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- 1.0 (* (- 1.0 y) z))))
(t_1 (+ x (* (- 1.0 y) (* (- z) x)))))
(if (< t_0 -1.618195973607049e+50)
t_1
(if (< t_0 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) t_1))))
double code(double x, double y, double z) {
double t_0 = x * (1.0 - ((1.0 - y) * z));
double t_1 = x + ((1.0 - y) * (-z * x));
double tmp;
if (t_0 < -1.618195973607049e+50) {
tmp = t_1;
} else if (t_0 < 3.892237649663903e+134) {
tmp = ((x * y) * z) - ((x * z) - 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 = x * (1.0d0 - ((1.0d0 - y) * z))
t_1 = x + ((1.0d0 - y) * (-z * x))
if (t_0 < (-1.618195973607049d+50)) then
tmp = t_1
else if (t_0 < 3.892237649663903d+134) then
tmp = ((x * y) * z) - ((x * z) - x)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - ((1.0 - y) * z));
double t_1 = x + ((1.0 - y) * (-z * x));
double tmp;
if (t_0 < -1.618195973607049e+50) {
tmp = t_1;
} else if (t_0 < 3.892237649663903e+134) {
tmp = ((x * y) * z) - ((x * z) - x);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x * (1.0 - ((1.0 - y) * z)) t_1 = x + ((1.0 - y) * (-z * x)) tmp = 0 if t_0 < -1.618195973607049e+50: tmp = t_1 elif t_0 < 3.892237649663903e+134: tmp = ((x * y) * z) - ((x * z) - x) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) t_1 = Float64(x + Float64(Float64(1.0 - y) * Float64(Float64(-z) * x))) tmp = 0.0 if (t_0 < -1.618195973607049e+50) tmp = t_1; elseif (t_0 < 3.892237649663903e+134) tmp = Float64(Float64(Float64(x * y) * z) - Float64(Float64(x * z) - x)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (1.0 - ((1.0 - y) * z)); t_1 = x + ((1.0 - y) * (-z * x)); tmp = 0.0; if (t_0 < -1.618195973607049e+50) tmp = t_1; elseif (t_0 < 3.892237649663903e+134) tmp = ((x * y) * z) - ((x * z) - x); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(N[(1.0 - y), $MachinePrecision] * N[((-z) * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[t$95$0, -1.618195973607049e+50], t$95$1, If[Less[t$95$0, 3.892237649663903e+134], N[(N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision] - N[(N[(x * z), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\
t_1 := x + \left(1 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\
\mathbf{if}\;t\_0 < -1.618195973607049 \cdot 10^{+50}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 < 3.892237649663903 \cdot 10^{+134}:\\
\;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
herbie shell --seed 2025015
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"
:precision binary64
:alt
(! :herbie-platform default (if (< (* x (- 1 (* (- 1 y) z))) -161819597360704900000000000000000000000000000000000) (+ x (* (- 1 y) (* (- z) x))) (if (< (* x (- 1 (* (- 1 y) z))) 389223764966390300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1 y) (* (- z) x))))))
(* x (- 1.0 (* (- 1.0 y) z))))