Assuming all costs have been equally split, and given
X = Initial purchase price of house,
Y = Current agreed market value [and do this formally],
A = initial mortgage capital balance (if any)
B = current mortgage capital balance (if any),
then I would say OP owes friend
(Y-X)/2 [takes account of capital appreciation]
+ (X-A)/2 [takes account of initial capital contribution]
+ (A-B)/2 [takes account of equity acquired through mortgage payments.
Handily, that simplifies to (Y-B)/2 - or
I would have thought OP owes
(y-whats owed to bank)/2
[can be easier to understand when all steps are spelled out]