<s>[INST] If $a,b$ are roots for $x^2+3x+1=0$.Calculating $(\frac{a}{b+1})^2 +(\frac{b}{a+1})^2$ If $a,b$ are roots for the equation $x^2+3x+1=0$.How to calculate $$\left(\frac{a}{b+1}\right)^2 +\left(\frac{b}{a+1}\right)^2$$
 [/INST] Because $x^2+3x+1=0$, we have $x^2=-3x-1$ and also $x^2+2x+1=-x$, for $x=a,b$. Hence $$\left(\frac{a}{b+1}\right)^2=\frac{a^2}{(b+1)^2}=\frac{-3a-1}{-b}=\frac{3a+1}{b}$$
By symmetry, the desired expression is $$\frac{3a+1}{b}+\frac{3b+1}{a}=\frac{3a^2+a}{ab}+\frac{3b^2+b}{ab}=\frac{3a^2+a+3b^2+b}{ab}=\frac{3(-3a-1)+a+3(-3b-1)+b}{ab}=\frac{-8(a+b)-6}{ab}$$
Lastly, because $a,b$ are roots of $x^2+3x+1$, we know that $ab=1$ and $a+b=-3$.  Plugging this into our final expression gives $$\frac{-8(-3)-6}{1}=18$$
</s>