a: \(\left(x+2\right)\left(x^2-2x+4\right)-\left(1-3x\right)\left(1+3x+9x^2\right)\)
\(=\left(x+2\right)\left(x^2-x\cdot2+2^2\right)+\left(3x-1\right)\left[\left(3x\right)^2+3x\cdot1+1^2\right]\)
\(=x^3+8+27x^3-1=28x^3+7\)
b: \(\left(x+y\right)\left(x^2-xy+y^2\right)+\left(2y-x\right)\left(x^2+2xy+4y^2\right)\)
\(=x^3+y^3+\left(2y\right)^3-x^3\)
\(=y^3+8y^3=9y^3\)