All you need to do is determine the relative portion of the house that each party owns at the time it is sold. This will start at 75/25 the day you buy the house, and then as you make mortgage repayments it will start to slowly converge towards the 57.5/42.5 split described above.
I'll be honest, I can't be bothered to try and write out a universal formula for this, but if you get one of the standard mortgage spreadsheets that illustrates for a given interest rate, term etc how much money is owed on a property over time, you can use that as a starting point for figuring out how much each person owns, by plugging in the total amount each person has paid in relative to the net value of the property after the outstanding mortgage balance is repaid.
So perhaps you buy a house for £100k, you start off paying £22.5k and £7.5k respectivley. If you sell the house on day 1 for £110k the net value after repaying mortgage would be say 110-70 = £40k. One person gets £30k back, the other gets £10k back.
Then suppose over time each person has paid in another £10k and the outstanding mortgage balance is down to say £55k. You sell the property for £115k. You've now got a net balance of £60k. Person 1 has paid in £32.5k and person 2 has paid in £17.5k. So Person 1 takes 32.5/(32.5+17.5)*£60k = £39k, Person 2 takes 17.5/(32.5+17.5)*£60k = £21k.