<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] We note that the expression given is a symmetric rational function of the roots of the original polynomial, so can be expressed in terms of the coefficients of the original polynomial. We then use the basic facts we know about the sum and product of the roots, and the fact that both $a$ and $b$ satisfy the polynomial to achieve successive simplification of otherwise unwieldy terms. Here are some hints for a way through.
Note that $a+b=-3$ and $ab=1$ so that $(a+1)(b+1)=ab+(a+b)+1=-3+2=-1$
Use this to put the whole thing over a common denominator and simplify.
Note also that $a^2(a+1)^2=a^2(a^2+2a+1)=a^2(a^2+3a+1-a)=-a^3$
You might also need to use $a^2+b^2=(a+b)^2-2ab$

Since the full answer closest in spirit to this has been deleted, note first $(a^2+b^2) = (-3)^2-2=7$. Then put the desired expression over common denominator $(a+1)^2(b+1)^2=1$ to obtain:$$a^2(a+1)^2+b^2(b+1)^2=-a^3-b^3=3(a^2+b^2)+(a+b)=21-3=18$$ [see comment for middle step]
</s>