How exciting! Could you clarify, are the 4 days at the end of his study program, so you'll have 4 free days and then need to be in London by the 4th night? Or 4 days at the beginning? It will make a difference in how long the days are since it stays light almost all night at the beginning of July. In any case, here are some ideas.
In St. Andrews itself you'll surely want to visit the British Golf Museum and enjoy lunch or tea in the cafe with its picture windows overlooking the Old Course 1st/18th hole. You can take the Old Course walking tour, but be aware it is not a walk of the entire course, but more of standing around at various spots in the 1st/18th hole vicinity, listening to anecdotes about one famous golfer after another and what they did for a given shot at a given tournament. IOW, it's fascinating for hardcore golf fans and relatively incomprehensible for the rest of us. You could play the Himalayas though this is probably more fun if you can find a few other people to make a threesome or foursome.
You can take a day trip to Dundee, where there's the new V&A design museum among other things to see and do.
You might look into renting a bike and spending a day riding along the coastal route toward Anstruther and back. I wouldn't be surprised if there are groups of cyclists doing this.
When your 4 free days arrive, I'd suggest booking a place in the area of Blairgowrie and Coupar Angus (i.e., near Glamis Castle) for 1-2 nights, then Edinburgh. Or if you are city people, then just stay in Edinburgh for the entire time; you'd then have time for a half-day excursion to Roslin Chapel, if that interests you.
To get from Edinburgh to London you could either take the train or fly. Hope this helps!