Build up the stamina and based on the fact that you'll spend as much time riding to Haymarket and waiting for the train as riding directly back it'll be faster just to ride the 4 miles.
Heading out of Edinburgh by train I usually go to Waverley, as a) its (almost) all downhill to the trains b) many trains start from Waverley, so you get on more easily. Inbound from the West the E-G timetables allow 7-8 minutes to get in to Waverley from Haymarket outbound the timetables allow 4 minutes, and the current timings mean a near guaranteed 40 minutes fast train time between Queen Street and Haymarket = less than 1 hour to most central venues.
Based on my London practice I'll ride up to 9 miles on the East-West axis (Thames Valley) and much less to the North (Highgate & other hills) unless there is a train departing immediately from an adjacent station or factors such as weather/fatigue are pressing
Urban riding depending on fitness, with no big load should average at around 12mph (as does touring for a fit rider) so 4 miles will take you 20 minutes without major exertion. Stamping down on the pedals might get you up in the 18-20mph range, especially if you can get the drafting effect from traffic on a busy road.
A folding bike will also go on a bus, and I was doing work in Loanhead a while back, which involved getting off the train at Haymarket and cutting over to Newington Road - if I spotted a bus I'd race it to the next stop and get on board to save the time and effort of bresting Liberton Brae, otherwise it took around the same time as waiting for a bus once past Cameron Toll.