
(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));
}
real(8) function code(x, y, z)
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 5 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));
}
real(8) function code(x, y, z)
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: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -5e+113) (* y (* z (- x))) (- x (* x (* y z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+113) {
tmp = y * (z * -x);
} else {
tmp = x - (x * (y * z));
}
return tmp;
}
NOTE: y and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y * z) <= (-5d+113)) then
tmp = y * (z * -x)
else
tmp = x - (x * (y * z))
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+113) {
tmp = y * (z * -x);
} else {
tmp = x - (x * (y * z));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -5e+113: tmp = y * (z * -x) else: tmp = x - (x * (y * z)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+113) tmp = Float64(y * Float64(z * Float64(-x))); else tmp = Float64(x - Float64(x * Float64(y * z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= -5e+113)
tmp = y * (z * -x);
else
tmp = x - (x * (y * z));
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+113], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+113}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5e113Initial program 87.6%
remove-double-neg87.6%
distribute-lft-neg-out87.6%
neg-mul-187.6%
*-commutative87.6%
associate-*r*87.6%
distribute-lft-neg-in87.6%
distribute-rgt-neg-out87.6%
*-commutative87.6%
neg-mul-187.6%
remove-double-neg87.6%
cancel-sign-sub-inv87.6%
+-commutative87.6%
distribute-lft-neg-out87.6%
metadata-eval87.6%
distribute-neg-in87.6%
fma-def87.6%
Simplified87.6%
Taylor expanded in y around inf 97.5%
mul-1-neg97.5%
distribute-rgt-neg-in97.5%
distribute-rgt-neg-in97.5%
Simplified97.5%
if -5e113 < (*.f64 y z) Initial program 98.2%
remove-double-neg98.2%
distribute-lft-neg-out98.2%
neg-mul-198.2%
*-commutative98.2%
associate-*r*98.2%
distribute-lft-neg-in98.2%
distribute-rgt-neg-out98.2%
*-commutative98.2%
neg-mul-198.2%
remove-double-neg98.2%
cancel-sign-sub-inv98.2%
+-commutative98.2%
distribute-lft-neg-out98.2%
metadata-eval98.2%
distribute-neg-in98.2%
fma-def98.2%
Simplified98.2%
fma-udef98.2%
distribute-neg-in98.2%
metadata-eval98.2%
+-commutative98.2%
distribute-rgt-in98.2%
*-un-lft-identity98.2%
*-commutative98.2%
distribute-rgt-neg-in98.2%
Applied egg-rr98.2%
distribute-rgt-neg-out98.2%
*-commutative98.2%
cancel-sign-sub-inv98.2%
*-commutative98.2%
*-commutative98.2%
Applied egg-rr98.2%
Final simplification98.1%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -5e+113) (* y (* z (- x))) (* x (- 1.0 (* y z)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+113) {
tmp = y * (z * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
NOTE: y and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y * z) <= (-5d+113)) then
tmp = y * (z * -x)
else
tmp = x * (1.0d0 - (y * z))
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+113) {
tmp = y * (z * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -5e+113: tmp = y * (z * -x) else: tmp = x * (1.0 - (y * z)) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+113) tmp = Float64(y * Float64(z * Float64(-x))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= -5e+113)
tmp = y * (z * -x);
else
tmp = x * (1.0 - (y * z));
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+113], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+113}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5e113Initial program 87.6%
remove-double-neg87.6%
distribute-lft-neg-out87.6%
neg-mul-187.6%
*-commutative87.6%
associate-*r*87.6%
distribute-lft-neg-in87.6%
distribute-rgt-neg-out87.6%
*-commutative87.6%
neg-mul-187.6%
remove-double-neg87.6%
cancel-sign-sub-inv87.6%
+-commutative87.6%
distribute-lft-neg-out87.6%
metadata-eval87.6%
distribute-neg-in87.6%
fma-def87.6%
Simplified87.6%
Taylor expanded in y around inf 97.5%
mul-1-neg97.5%
distribute-rgt-neg-in97.5%
distribute-rgt-neg-in97.5%
Simplified97.5%
if -5e113 < (*.f64 y z) Initial program 98.2%
Final simplification98.1%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.9e-148) (not (<= z 3.1e+64))) (* x (* y (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e-148) || !(z <= 3.1e+64)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
NOTE: y and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-1.9d-148)) .or. (.not. (z <= 3.1d+64))) then
tmp = x * (y * -z)
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e-148) || !(z <= 3.1e+64)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (z <= -1.9e-148) or not (z <= 3.1e+64): tmp = x * (y * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.9e-148) || !(z <= 3.1e+64)) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.9e-148) || ~((z <= 3.1e+64)))
tmp = x * (y * -z);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -1.9e-148], N[Not[LessEqual[z, 3.1e+64]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{-148} \lor \neg \left(z \leq 3.1 \cdot 10^{+64}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.90000000000000007e-148 or 3.0999999999999999e64 < z Initial program 94.3%
Taylor expanded in y around inf 59.8%
associate-*r*59.8%
neg-mul-159.8%
*-commutative59.8%
Simplified59.8%
if -1.90000000000000007e-148 < z < 3.0999999999999999e64Initial program 99.9%
remove-double-neg99.9%
distribute-lft-neg-out99.9%
neg-mul-199.9%
*-commutative99.9%
associate-*r*99.9%
distribute-lft-neg-in99.9%
distribute-rgt-neg-out99.9%
*-commutative99.9%
neg-mul-199.9%
remove-double-neg99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
distribute-lft-neg-out99.9%
metadata-eval99.9%
distribute-neg-in99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 77.2%
Final simplification66.9%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -1.9e-148) (* x (* y (- z))) (if (<= z 2.05e+64) x (* y (* z (- x))))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= -1.9e-148) {
tmp = x * (y * -z);
} else if (z <= 2.05e+64) {
tmp = x;
} else {
tmp = y * (z * -x);
}
return tmp;
}
NOTE: y and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.9d-148)) then
tmp = x * (y * -z)
else if (z <= 2.05d+64) then
tmp = x
else
tmp = y * (z * -x)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.9e-148) {
tmp = x * (y * -z);
} else if (z <= 2.05e+64) {
tmp = x;
} else {
tmp = y * (z * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if z <= -1.9e-148: tmp = x * (y * -z) elif z <= 2.05e+64: tmp = x else: tmp = y * (z * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (z <= -1.9e-148) tmp = Float64(x * Float64(y * Float64(-z))); elseif (z <= 2.05e+64) tmp = x; else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -1.9e-148)
tmp = x * (y * -z);
elseif (z <= 2.05e+64)
tmp = x;
else
tmp = y * (z * -x);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[z, -1.9e-148], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.05e+64], x, N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{-148}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{elif}\;z \leq 2.05 \cdot 10^{+64}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if z < -1.90000000000000007e-148Initial program 96.1%
Taylor expanded in y around inf 53.7%
associate-*r*53.7%
neg-mul-153.7%
*-commutative53.7%
Simplified53.7%
if -1.90000000000000007e-148 < z < 2.04999999999999989e64Initial program 99.9%
remove-double-neg99.9%
distribute-lft-neg-out99.9%
neg-mul-199.9%
*-commutative99.9%
associate-*r*99.9%
distribute-lft-neg-in99.9%
distribute-rgt-neg-out99.9%
*-commutative99.9%
neg-mul-199.9%
remove-double-neg99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
distribute-lft-neg-out99.9%
metadata-eval99.9%
distribute-neg-in99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 77.2%
if 2.04999999999999989e64 < z Initial program 90.9%
remove-double-neg90.9%
distribute-lft-neg-out90.9%
neg-mul-190.9%
*-commutative90.9%
associate-*r*90.9%
distribute-lft-neg-in90.9%
distribute-rgt-neg-out90.9%
*-commutative90.9%
neg-mul-190.9%
remove-double-neg90.9%
cancel-sign-sub-inv90.9%
+-commutative90.9%
distribute-lft-neg-out90.9%
metadata-eval90.9%
distribute-neg-in90.9%
fma-def90.9%
Simplified90.9%
Taylor expanded in y around inf 77.9%
mul-1-neg77.9%
distribute-rgt-neg-in77.9%
distribute-rgt-neg-in77.9%
Simplified77.9%
Final simplification68.3%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: y and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
assert y < z;
public static double code(double x, double y, double z) {
return x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x
y, z = sort([y, z]) function code(x, y, z) return x end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x
\end{array}
Initial program 96.6%
remove-double-neg96.6%
distribute-lft-neg-out96.6%
neg-mul-196.6%
*-commutative96.6%
associate-*r*96.6%
distribute-lft-neg-in96.6%
distribute-rgt-neg-out96.6%
*-commutative96.6%
neg-mul-196.6%
remove-double-neg96.6%
cancel-sign-sub-inv96.6%
+-commutative96.6%
distribute-lft-neg-out96.6%
metadata-eval96.6%
distribute-neg-in96.6%
fma-def96.6%
Simplified96.6%
Taylor expanded in y around 0 52.3%
Final simplification52.3%
herbie shell --seed 2023268
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))