
(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 7 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: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* z y) -5.2e+174) (* y (* x (- z))) (if (<= (* z y) 1e+105) (* x (- 1.0 (* z y))) (* z (* x (- y))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z * y) <= -5.2e+174) {
tmp = y * (x * -z);
} else if ((z * y) <= 1e+105) {
tmp = x * (1.0 - (z * y));
} else {
tmp = z * (x * -y);
}
return tmp;
}
NOTE: x, 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 * y) <= (-5.2d+174)) then
tmp = y * (x * -z)
else if ((z * y) <= 1d+105) then
tmp = x * (1.0d0 - (z * y))
else
tmp = z * (x * -y)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z * y) <= -5.2e+174) {
tmp = y * (x * -z);
} else if ((z * y) <= 1e+105) {
tmp = x * (1.0 - (z * y));
} else {
tmp = z * (x * -y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z * y) <= -5.2e+174: tmp = y * (x * -z) elif (z * y) <= 1e+105: tmp = x * (1.0 - (z * y)) else: tmp = z * (x * -y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(z * y) <= -5.2e+174) tmp = Float64(y * Float64(x * Float64(-z))); elseif (Float64(z * y) <= 1e+105) tmp = Float64(x * Float64(1.0 - Float64(z * y))); else tmp = Float64(z * Float64(x * Float64(-y))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z * y) <= -5.2e+174)
tmp = y * (x * -z);
elseif ((z * y) <= 1e+105)
tmp = x * (1.0 - (z * y));
else
tmp = z * (x * -y);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(z * y), $MachinePrecision], -5.2e+174], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * y), $MachinePrecision], 1e+105], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot y \leq -5.2 \cdot 10^{+174}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{elif}\;z \cdot y \leq 10^{+105}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5.1999999999999997e174Initial program 87.0%
Taylor expanded in y around inf 87.0%
*-commutative87.0%
associate-*r*87.0%
neg-mul-187.0%
distribute-rgt-neg-in87.0%
associate-*l*99.8%
distribute-lft-neg-in99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -5.1999999999999997e174 < (*.f64 y z) < 9.9999999999999994e104Initial program 99.9%
if 9.9999999999999994e104 < (*.f64 y z) Initial program 80.3%
Taylor expanded in z around inf 80.3%
Taylor expanded in z around inf 80.3%
associate-*r*99.7%
*-commutative99.7%
*-commutative99.7%
neg-mul-199.7%
distribute-lft-neg-in99.7%
Simplified99.7%
Final simplification99.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 3.3e-101) (- x (* z (* x y))) (* x (fma z (- y) 1.0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 3.3e-101) {
tmp = x - (z * (x * y));
} else {
tmp = x * fma(z, -y, 1.0);
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 3.3e-101) tmp = Float64(x - Float64(z * Float64(x * y))); else tmp = Float64(x * fma(z, Float64(-y), 1.0)); 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, 3.3e-101], N[(x - N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(z * (-y) + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.3 \cdot 10^{-101}:\\
\;\;\;\;x - z \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(z, -y, 1\right)\\
\end{array}
\end{array}
if x < 3.29999999999999984e-101Initial program 92.5%
Taylor expanded in y around 0 92.5%
mul-1-neg92.5%
*-commutative92.5%
associate-*l*92.9%
*-commutative92.9%
Simplified92.9%
unsub-neg92.9%
associate-*r*96.7%
*-commutative96.7%
Applied egg-rr96.7%
if 3.29999999999999984e-101 < x Initial program 99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
*-commutative99.9%
fma-define99.9%
Simplified99.9%
Final simplification97.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.4e-102) (not (<= z 1.05e+78))) (* z (* x (- y))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.4e-102) || !(z <= 1.05e+78)) {
tmp = z * (x * -y);
} else {
tmp = x;
}
return tmp;
}
NOTE: x, 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.4d-102)) .or. (.not. (z <= 1.05d+78))) then
tmp = z * (x * -y)
else
tmp = x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.4e-102) || !(z <= 1.05e+78)) {
tmp = z * (x * -y);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -1.4e-102) or not (z <= 1.05e+78): tmp = z * (x * -y) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.4e-102) || !(z <= 1.05e+78)) tmp = Float64(z * Float64(x * Float64(-y))); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.4e-102) || ~((z <= 1.05e+78)))
tmp = z * (x * -y);
else
tmp = 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_] := If[Or[LessEqual[z, -1.4e-102], N[Not[LessEqual[z, 1.05e+78]], $MachinePrecision]], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{-102} \lor \neg \left(z \leq 1.05 \cdot 10^{+78}\right):\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.40000000000000006e-102 or 1.05e78 < z Initial program 89.4%
Taylor expanded in z around inf 89.4%
Taylor expanded in z around inf 67.0%
associate-*r*74.2%
*-commutative74.2%
*-commutative74.2%
neg-mul-174.2%
distribute-lft-neg-in74.2%
Simplified74.2%
if -1.40000000000000006e-102 < z < 1.05e78Initial program 99.9%
Taylor expanded in y around 0 75.4%
Final simplification74.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.4e-102) (not (<= z 2.3e+78))) (* y (* x (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.4e-102) || !(z <= 2.3e+78)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
NOTE: x, 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.4d-102)) .or. (.not. (z <= 2.3d+78))) then
tmp = y * (x * -z)
else
tmp = x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.4e-102) || !(z <= 2.3e+78)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -1.4e-102) or not (z <= 2.3e+78): tmp = y * (x * -z) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.4e-102) || !(z <= 2.3e+78)) tmp = Float64(y * Float64(x * Float64(-z))); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.4e-102) || ~((z <= 2.3e+78)))
tmp = y * (x * -z);
else
tmp = 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_] := If[Or[LessEqual[z, -1.4e-102], N[Not[LessEqual[z, 2.3e+78]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{-102} \lor \neg \left(z \leq 2.3 \cdot 10^{+78}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.40000000000000006e-102 or 2.3000000000000002e78 < z Initial program 89.4%
Taylor expanded in y around inf 67.0%
*-commutative67.0%
associate-*r*67.0%
neg-mul-167.0%
distribute-rgt-neg-in67.0%
associate-*l*70.7%
distribute-lft-neg-in70.7%
distribute-rgt-neg-in70.7%
Simplified70.7%
if -1.40000000000000006e-102 < z < 2.3000000000000002e78Initial program 99.9%
Taylor expanded in y around 0 75.4%
Final simplification73.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.4e-102) (not (<= z 1.1e+78))) (* x (* y (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.4e-102) || !(z <= 1.1e+78)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
NOTE: x, 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.4d-102)) .or. (.not. (z <= 1.1d+78))) then
tmp = x * (y * -z)
else
tmp = x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.4e-102) || !(z <= 1.1e+78)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -1.4e-102) or not (z <= 1.1e+78): tmp = x * (y * -z) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.4e-102) || !(z <= 1.1e+78)) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.4e-102) || ~((z <= 1.1e+78)))
tmp = x * (y * -z);
else
tmp = 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_] := If[Or[LessEqual[z, -1.4e-102], N[Not[LessEqual[z, 1.1e+78]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{-102} \lor \neg \left(z \leq 1.1 \cdot 10^{+78}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.40000000000000006e-102 or 1.10000000000000007e78 < z Initial program 89.4%
Taylor expanded in y around inf 67.0%
neg-mul-167.0%
distribute-rgt-neg-in67.0%
Simplified67.0%
if -1.40000000000000006e-102 < z < 1.10000000000000007e78Initial program 99.9%
Taylor expanded in y around 0 75.4%
Final simplification71.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 3.2e-101) (- x (* z (* x y))) (* x (- 1.0 (* z y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 3.2e-101) {
tmp = x - (z * (x * y));
} else {
tmp = x * (1.0 - (z * y));
}
return tmp;
}
NOTE: x, 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 (x <= 3.2d-101) then
tmp = x - (z * (x * y))
else
tmp = x * (1.0d0 - (z * y))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (x <= 3.2e-101) {
tmp = x - (z * (x * y));
} else {
tmp = x * (1.0 - (z * y));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= 3.2e-101: tmp = x - (z * (x * y)) else: tmp = x * (1.0 - (z * y)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 3.2e-101) tmp = Float64(x - Float64(z * Float64(x * y))); else tmp = Float64(x * Float64(1.0 - Float64(z * y))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= 3.2e-101)
tmp = x - (z * (x * y));
else
tmp = x * (1.0 - (z * y));
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[x, 3.2e-101], N[(x - N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.2 \cdot 10^{-101}:\\
\;\;\;\;x - z \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\end{array}
\end{array}
if x < 3.19999999999999978e-101Initial program 92.5%
Taylor expanded in y around 0 92.5%
mul-1-neg92.5%
*-commutative92.5%
associate-*l*92.9%
*-commutative92.9%
Simplified92.9%
unsub-neg92.9%
associate-*r*96.7%
*-commutative96.7%
Applied egg-rr96.7%
if 3.19999999999999978e-101 < x Initial program 99.9%
Final simplification97.7%
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.
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 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 94.7%
Taylor expanded in y around 0 50.5%
herbie shell --seed 2024163
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))