set XX = [:X,(the carrier of M \ {a}):] \/ {[X,a]};
defpred S1[ set , set , set ] means for x, y being Element of [:X,(the carrier of M \ {a}):] \/ {[X,a]} st x = $1 & y = $2 holds
for x1, y1 being set
for x2, y2 being Point of st x = [x1,x2] & y = [y1,y2] holds
( ( x1 = y1 implies $3 = dist x2,y2 ) & ( x1 <> y1 implies $3 = (dist x2,a) + (dist a,y2) ) );
A1: for x, y being set st x in [:X,(the carrier of M \ {a}):] \/ {[X,a]} & y in [:X,(the carrier of M \ {a}):] \/ {[X,a]} holds
ex z being set st
( z in REAL & S1[x,y,z] )
proof
let x, y be set ; :: thesis: ( x in [:X,(the carrier of M \ {a}):] \/ {[X,a]} & y in [:X,(the carrier of M \ {a}):] \/ {[X,a]} implies ex z being set st
( z in REAL & S1[x,y,z] ) )

assume that
A2: x in [:X,(the carrier of M \ {a}):] \/ {[X,a]} and
A3: y in [:X,(the carrier of M \ {a}):] \/ {[X,a]} ; :: thesis: ex z being set st
( z in REAL & S1[x,y,z] )

consider y1 being set , y2 being Point of such that
A4: y = [y1,y2] and
( ( y1 in X & y2 <> a ) or ( y1 = X & y2 = a ) ) by A3, Th38;
consider x1 being set , x2 being Point of such that
A5: x = [x1,x2] and
( ( x1 in X & x2 <> a ) or ( x1 = X & x2 = a ) ) by A2, Th38;
now
per cases ( x1 = y1 or x1 <> y1 ) ;
suppose A6: x1 = y1 ; :: thesis: ex d being Element of REAL st
( d in REAL & ( for x', y' being Element of [:X,(the carrier of M \ {a}):] \/ {[X,a]} st x' = x & y' = y holds
for x1', y1' being set
for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) ) ) )

take d = dist x2,y2; :: thesis: ( d in REAL & ( for x', y' being Element of [:X,(the carrier of M \ {a}):] \/ {[X,a]} st x' = x & y' = y holds
for x1', y1' being set
for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) ) ) )

thus d in REAL ; :: thesis: for x', y' being Element of [:X,(the carrier of M \ {a}):] \/ {[X,a]} st x' = x & y' = y holds
for x1', y1' being set
for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) )

let x', y' be Element of [:X,(the carrier of M \ {a}):] \/ {[X,a]}; :: thesis: ( x' = x & y' = y implies for x1', y1' being set
for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) ) )

assume that
A7: x' = x and
A8: y' = y ; :: thesis: for x1', y1' being set
for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) )

let x1', y1' be set ; :: thesis: for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) )

let x2', y2' be Point of ; :: thesis: ( x' = [x1',x2'] & y' = [y1',y2'] implies ( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) ) )
assume that
A9: x' = [x1',x2'] and
A10: y' = [y1',y2'] ; :: thesis: ( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) )
A11: x2' = x2 by A5, A7, A9, ZFMISC_1:33;
x1' = x1 by A5, A7, A9, ZFMISC_1:33;
hence ( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) ) by A4, A6, A8, A10, A11, ZFMISC_1:33; :: thesis: verum
end;
suppose A12: x1 <> y1 ; :: thesis: ex d being Element of REAL st
( d in REAL & ( for x', y' being Element of [:X,(the carrier of M \ {a}):] \/ {[X,a]} st x' = x & y' = y holds
for x1', y1' being set
for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) ) ) )

take d = (dist x2,a) + (dist a,y2); :: thesis: ( d in REAL & ( for x', y' being Element of [:X,(the carrier of M \ {a}):] \/ {[X,a]} st x' = x & y' = y holds
for x1', y1' being set
for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) ) ) )

thus d in REAL ; :: thesis: for x', y' being Element of [:X,(the carrier of M \ {a}):] \/ {[X,a]} st x' = x & y' = y holds
for x1', y1' being set
for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) )

let x', y' be Element of [:X,(the carrier of M \ {a}):] \/ {[X,a]}; :: thesis: ( x' = x & y' = y implies for x1', y1' being set
for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) ) )

assume that
A13: x' = x and
A14: y' = y ; :: thesis: for x1', y1' being set
for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) )

let x1', y1' be set ; :: thesis: for x2', y2' being Point of st x' = [x1',x2'] & y' = [y1',y2'] holds
( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) )

let x2', y2' be Point of ; :: thesis: ( x' = [x1',x2'] & y' = [y1',y2'] implies ( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) ) )
assume that
A15: x' = [x1',x2'] and
A16: y' = [y1',y2'] ; :: thesis: ( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) )
A17: x2' = x2 by A5, A13, A15, ZFMISC_1:33;
x1' = x1 by A5, A13, A15, ZFMISC_1:33;
hence ( ( x1' = y1' implies d = dist x2',y2' ) & ( x1' <> y1' implies d = (dist x2',a) + (dist a,y2') ) ) by A4, A12, A14, A16, A17, ZFMISC_1:33; :: thesis: verum
end;
end;
end;
hence ex z being set st
( z in REAL & S1[x,y,z] ) ; :: thesis: verum
end;
consider f being Function of [:([:X,(the carrier of M \ {a}):] \/ {[X,a]}),([:X,(the carrier of M \ {a}):] \/ {[X,a]}):], REAL such that
A18: for x, y being set st x in [:X,(the carrier of M \ {a}):] \/ {[X,a]} & y in [:X,(the carrier of M \ {a}):] \/ {[X,a]} holds
S1[x,y,f . x,y] from BINOP_1:sch 1(A1);
take f ; :: thesis: for x, y being Element of [:X,(the carrier of M \ {a}):] \/ {[X,a]}
for x1, y1 being set
for x2, y2 being Point of st x = [x1,x2] & y = [y1,y2] holds
( ( x1 = y1 implies f . x,y = dist x2,y2 ) & ( x1 <> y1 implies f . x,y = (dist x2,a) + (dist a,y2) ) )

thus for x, y being Element of [:X,(the carrier of M \ {a}):] \/ {[X,a]}
for x1, y1 being set
for x2, y2 being Point of st x = [x1,x2] & y = [y1,y2] holds
( ( x1 = y1 implies f . x,y = dist x2,y2 ) & ( x1 <> y1 implies f . x,y = (dist x2,a) + (dist a,y2) ) ) by A18; :: thesis: verum