I was reading this answer that shows how to calculate the inverse of public exponent, i got to the point where we apply the euclidean algorithm and finish substituting to get
(40−2×17)−1×(17−2×(40−2×17))=1
it states "this is a linear combination of 17 and 40, after simplifying you get:"
(−7)×17+3×40=1
which gives us the d = -7
but i'm stuck as to how we simplified down to
(−7)×17+3×40=1
from:
(40−2×17)−1×(17−2×(40−2×17))=1
i would be grateful if someone could explain it to me
Thanks in advance