How to differentiate using Chain Rule