
(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: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -2e+184) (* y (* x (- z))) (if (<= (* y z) 5e+107) (* x (- 1.0 (* y z))) (* z (* x (- y))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2e+184) {
tmp = y * (x * -z);
} else if ((y * z) <= 5e+107) {
tmp = x * (1.0 - (y * z));
} 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 ((y * z) <= (-2d+184)) then
tmp = y * (x * -z)
else if ((y * z) <= 5d+107) then
tmp = x * (1.0d0 - (y * z))
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 ((y * z) <= -2e+184) {
tmp = y * (x * -z);
} else if ((y * z) <= 5e+107) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (x * -y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -2e+184: tmp = y * (x * -z) elif (y * z) <= 5e+107: tmp = x * (1.0 - (y * z)) else: tmp = z * (x * -y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2e+184) tmp = Float64(y * Float64(x * Float64(-z))); elseif (Float64(y * z) <= 5e+107) tmp = Float64(x * Float64(1.0 - Float64(y * z))); 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 ((y * z) <= -2e+184)
tmp = y * (x * -z);
elseif ((y * z) <= 5e+107)
tmp = x * (1.0 - (y * z));
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[(y * z), $MachinePrecision], -2e+184], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 5e+107], N[(x * N[(1.0 - N[(y * z), $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}\;y \cdot z \leq -2 \cdot 10^{+184}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{+107}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -2.00000000000000003e184Initial program 85.6%
Taylor expanded in y around inf 85.6%
mul-1-neg85.6%
associate-*r*99.8%
distribute-rgt-neg-in99.8%
*-commutative99.8%
associate-*r*99.9%
distribute-rgt-neg-out99.9%
Simplified99.9%
if -2.00000000000000003e184 < (*.f64 y z) < 5.0000000000000002e107Initial program 99.9%
if 5.0000000000000002e107 < (*.f64 y z) Initial program 82.4%
Taylor expanded in y around inf 82.4%
mul-1-neg82.4%
associate-*r*97.7%
Simplified97.7%
Final simplification99.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -4e+84) (not (<= y 6.5e-23))) (* z (* x (- y))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e+84) || !(y <= 6.5e-23)) {
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 ((y <= (-4d+84)) .or. (.not. (y <= 6.5d-23))) 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 ((y <= -4e+84) || !(y <= 6.5e-23)) {
tmp = z * (x * -y);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -4e+84) or not (y <= 6.5e-23): 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 ((y <= -4e+84) || !(y <= 6.5e-23)) 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 ((y <= -4e+84) || ~((y <= 6.5e-23)))
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[y, -4e+84], N[Not[LessEqual[y, 6.5e-23]], $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}\;y \leq -4 \cdot 10^{+84} \lor \neg \left(y \leq 6.5 \cdot 10^{-23}\right):\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.00000000000000023e84 or 6.5e-23 < y Initial program 90.2%
Taylor expanded in y around inf 58.8%
mul-1-neg58.8%
associate-*r*64.3%
Simplified64.3%
if -4.00000000000000023e84 < y < 6.5e-23Initial program 99.9%
Taylor expanded in y around 0 77.4%
Final simplification71.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -3.1e+88) (* y (* x (- z))) (if (<= y 1.4e-25) x (* z (* x (- y))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -3.1e+88) {
tmp = y * (x * -z);
} else if (y <= 1.4e-25) {
tmp = x;
} 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 (y <= (-3.1d+88)) then
tmp = y * (x * -z)
else if (y <= 1.4d-25) then
tmp = x
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 (y <= -3.1e+88) {
tmp = y * (x * -z);
} else if (y <= 1.4e-25) {
tmp = x;
} else {
tmp = z * (x * -y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -3.1e+88: tmp = y * (x * -z) elif y <= 1.4e-25: tmp = x else: tmp = z * (x * -y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -3.1e+88) tmp = Float64(y * Float64(x * Float64(-z))); elseif (y <= 1.4e-25) tmp = x; 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 (y <= -3.1e+88)
tmp = y * (x * -z);
elseif (y <= 1.4e-25)
tmp = x;
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[y, -3.1e+88], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.4e-25], x, N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{+88}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-25}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if y < -3.1000000000000001e88Initial program 93.2%
Taylor expanded in y around inf 70.6%
mul-1-neg70.6%
associate-*r*70.8%
distribute-rgt-neg-in70.8%
*-commutative70.8%
associate-*r*72.2%
distribute-rgt-neg-out72.2%
Simplified72.2%
if -3.1000000000000001e88 < y < 1.39999999999999994e-25Initial program 99.2%
Taylor expanded in y around 0 77.4%
if 1.39999999999999994e-25 < y Initial program 89.1%
Taylor expanded in y around inf 50.8%
mul-1-neg50.8%
associate-*r*59.1%
Simplified59.1%
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 2e+17) (- x (* y (* x z))) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 2e+17) {
tmp = x - (y * (x * z));
} else {
tmp = x * (1.0 - (y * z));
}
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 <= 2d+17) then
tmp = x - (y * (x * z))
else
tmp = x * (1.0d0 - (y * z))
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 <= 2e+17) {
tmp = x - (y * (x * z));
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= 2e+17: tmp = x - (y * (x * z)) 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 <= 2e+17) tmp = Float64(x - Float64(y * Float64(x * z))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= 2e+17)
tmp = x - (y * (x * z));
else
tmp = x * (1.0 - (y * z));
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, 2e+17], N[(x - N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision]), $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 2 \cdot 10^{+17}:\\
\;\;\;\;x - y \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if x < 2e17Initial program 93.4%
sub-neg93.4%
distribute-rgt-in93.4%
*-un-lft-identity93.4%
distribute-rgt-neg-in93.4%
Applied egg-rr93.4%
associate-*l*95.0%
distribute-lft-neg-in95.0%
*-commutative95.0%
distribute-rgt-neg-out95.0%
distribute-lft-neg-in95.0%
add-sqr-sqrt57.8%
sqrt-unprod70.1%
sqr-neg70.1%
sqrt-unprod35.8%
add-sqr-sqrt56.4%
*-commutative56.4%
distribute-lft-neg-in56.4%
cancel-sign-sub-inv56.4%
associate-*l*56.8%
*-commutative56.8%
associate-*r*54.3%
*-commutative54.3%
associate-*r*56.4%
distribute-rgt-neg-in56.4%
add-sqr-sqrt35.8%
sqrt-unprod70.1%
Applied egg-rr95.0%
if 2e17 < x Initial program 100.0%
Final simplification96.3%
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 95.1%
Taylor expanded in y around 0 55.9%
Final simplification55.9%
herbie shell --seed 2023318
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))