\(x\left(x-y\right)^2-y\left(x-y\right)^2+xy^2-x^2y\)
\(=\left(x-y\right)^2\left(x-y\right)-xy\left(x-y\right)\)
\(=\left(x-y\right)\left(x^2-2xy+y^2-xy\right)\)
\(=\left(x-y\right)\left(x^2-3xy+y^2\right)\)
x(x-y)2 -y(x-y)2+xy2-x2y=x(x-y)2 -y(x-y)2+(xy2-x2y)=x(x-y)2 -y(x-y)2+xy(x-y)=\(\left(x-y\right)\left[x\left(x-y\right)-y\left(x-y\right)+xy\right]\)=\(\left(x-y\right)\left[\left(x-y\right)^2+xy\right]\)