Hello! I need your help over a little thing.

I have a function of this type

X= 5-p if p<4

2- p/4 if 4<=p< 8

0 if p> = 8

knowing that R=X *p

and MR= R' (meaning derivative, and expressing the p in terms of the X)

I have

MR= 8- 8X if 0<X<1

5 -2X if X>=1

My problem is in the MR.

I get why we have the value 8-8X and so on, but I do not get how to have the if part. How do we pass from the if part written in terms of p, to the if part written in terms of X? Thanks for all your help.