:: METRIC_1 semantic presentation

definition
attr a1 is strict;
struct MetrStruct -> 1-sorted ;
aggr MetrStruct(# carrier, distance #) -> MetrStruct ;
sel distance c1 -> Function of [:the carrier of a1,the carrier of a1:], REAL ;
end;

registration
cluster non empty strict MetrStruct ;
existence
ex b1 being MetrStruct st
( not b1 is empty & b1 is strict )
proof end;
end;

definition
let c1, c2 be set ;
let c3 be PartFunc of [:c1,c2:], REAL ;
let c4 be Element of c1;
let c5 be Element of c2;
redefine func . as c3 . c4,c5 -> Real;
coherence
c3 . c4,c5 is Real
proof end;
end;

definition
let c1 be MetrStruct ;
let c2, c3 be Element of c1;
func dist c2,c3 -> Real equals :: METRIC_1:def 1
the distance of a1 . a2,a3;
coherence
the distance of c1 . c2,c3 is Real
;
end;

:: deftheorem Def1 defines dist METRIC_1:def 1 :
for b1 being MetrStruct
for b2, b3 being Element of b1 holds dist b2,b3 = the distance of b1 . b2,b3;

definition
func Empty^2-to-zero -> Function of [:{{} },{{} }:], REAL equals :: METRIC_1:def 2
[:{{} },{{} }:] --> 0;
coherence
[:{{} },{{} }:] --> 0 is Function of [:{{} },{{} }:], REAL
proof end;
end;

:: deftheorem Def2 defines Empty^2-to-zero METRIC_1:def 2 :
Empty^2-to-zero = [:{{} },{{} }:] --> 0;

Lemma1: [{} ,{} ] in [:{{} },{{} }:]
by ZFMISC_1:34;

E2: Empty^2-to-zero . {} ,{} = Empty^2-to-zero . [{} ,{} ]
.= 0 by Lemma1, FUNCOP_1:13 ;

Lemma3: for b1, b2 being Element of {{} } holds
( Empty^2-to-zero . b1,b2 = 0 iff b1 = b2 )
proof end;

Lemma4: for b1, b2 being Element of {{} } holds Empty^2-to-zero . b1,b2 = Empty^2-to-zero . b2,b1
proof end;

Lemma5: for b1, b2, b3 being Element of {{} } holds Empty^2-to-zero . b1,b3 <= (Empty^2-to-zero . b1,b2) + (Empty^2-to-zero . b2,b3)
proof end;

definition
let c1 be set ;
let c2 be PartFunc of [:c1,c1:], REAL ;
attr a2 is Reflexive means :Def3: :: METRIC_1:def 3
for b1 being Element of a1 holds a2 . b1,b1 = 0;
attr a2 is discerning means :Def4: :: METRIC_1:def 4
for b1, b2 being Element of a1 st a2 . b1,b2 = 0 holds
b1 = b2;
attr a2 is symmetric means :Def5: :: METRIC_1:def 5
for b1, b2 being Element of a1 holds a2 . b1,b2 = a2 . b2,b1;
attr a2 is triangle means :Def6: :: METRIC_1:def 6
for b1, b2, b3 being Element of a1 holds a2 . b1,b3 <= (a2 . b1,b2) + (a2 . b2,b3);
end;

:: deftheorem Def3 defines Reflexive METRIC_1:def 3 :
for b1 being set
for b2 being PartFunc of [:b1,b1:], REAL holds
( b2 is Reflexive iff for b3 being Element of b1 holds b2 . b3,b3 = 0 );

:: deftheorem Def4 defines discerning METRIC_1:def 4 :
for b1 being set
for b2 being PartFunc of [:b1,b1:], REAL holds
( b2 is discerning iff for b3, b4 being Element of b1 st b2 . b3,b4 = 0 holds
b3 = b4 );

:: deftheorem Def5 defines symmetric METRIC_1:def 5 :
for b1 being set
for b2 being PartFunc of [:b1,b1:], REAL holds
( b2 is symmetric iff for b3, b4 being Element of b1 holds b2 . b3,b4 = b2 . b4,b3 );

:: deftheorem Def6 defines triangle METRIC_1:def 6 :
for b1 being set
for b2 being PartFunc of [:b1,b1:], REAL holds
( b2 is triangle iff for b3, b4, b5 being Element of b1 holds b2 . b3,b5 <= (b2 . b3,b4) + (b2 . b4,b5) );

definition
let c1 be MetrStruct ;
attr a1 is Reflexive means :Def7: :: METRIC_1:def 7
the distance of a1 is Reflexive;
attr a1 is discerning means :Def8: :: METRIC_1:def 8
the distance of a1 is discerning;
attr a1 is symmetric means :Def9: :: METRIC_1:def 9
the distance of a1 is symmetric;
attr a1 is triangle means :Def10: :: METRIC_1:def 10
the distance of a1 is triangle;
end;

:: deftheorem Def7 defines Reflexive METRIC_1:def 7 :
for b1 being MetrStruct holds
( b1 is Reflexive iff the distance of b1 is Reflexive );

:: deftheorem Def8 defines discerning METRIC_1:def 8 :
for b1 being MetrStruct holds
( b1 is discerning iff the distance of b1 is discerning );

:: deftheorem Def9 defines symmetric METRIC_1:def 9 :
for b1 being MetrStruct holds
( b1 is symmetric iff the distance of b1 is symmetric );

:: deftheorem Def10 defines triangle METRIC_1:def 10 :
for b1 being MetrStruct holds
( b1 is triangle iff the distance of b1 is triangle );

registration
cluster non empty strict Reflexive discerning symmetric triangle MetrStruct ;
existence
ex b1 being MetrStruct st
( b1 is strict & b1 is Reflexive & b1 is discerning & b1 is symmetric & b1 is triangle & not b1 is empty )
proof end;
end;

definition
mode MetrSpace is Reflexive discerning symmetric triangle MetrStruct ;
end;

theorem Th1: :: METRIC_1:1
for b1 being MetrStruct holds
( ( for b2 being Element of b1 holds dist b2,b2 = 0 ) iff b1 is Reflexive )
proof end;

theorem Th2: :: METRIC_1:2
for b1 being MetrStruct holds
( ( for b2, b3 being Element of b1 st dist b2,b3 = 0 holds
b2 = b3 ) iff b1 is discerning )
proof end;

theorem Th3: :: METRIC_1:3
for b1 being MetrStruct holds
( ( for b2, b3 being Element of b1 holds dist b2,b3 = dist b3,b2 ) iff b1 is symmetric )
proof end;

theorem Th4: :: METRIC_1:4
for b1 being MetrStruct holds
( ( for b2, b3, b4 being Element of b1 holds dist b2,b4 <= (dist b2,b3) + (dist b3,b4) ) iff b1 is triangle )
proof end;

definition
let c1 be symmetric MetrStruct ;
let c2, c3 be Element of c1;
redefine func dist as dist c2,c3 -> Real;
commutativity
for b1, b2 being Element of c1 holds dist b1,b2 = dist b2,b1
by Th3;
end;

theorem Th5: :: METRIC_1:5
for b1 being Reflexive symmetric triangle MetrStruct
for b2, b3 being Element of b1 holds 0 <= dist b2,b3
proof end;

theorem Th6: :: METRIC_1:6
for b1 being MetrStruct st ( for b2, b3, b4 being Element of b1 holds
( ( dist b2,b3 = 0 implies b2 = b3 ) & ( b2 = b3 implies dist b2,b3 = 0 ) & dist b2,b3 = dist b3,b2 & dist b2,b4 <= (dist b2,b3) + (dist b3,b4) ) ) holds
b1 is MetrSpace
proof end;

definition
let c1 be set ;
func discrete_dist c1 -> Function of [:a1,a1:], REAL means :Def11: :: METRIC_1:def 11
for b1, b2 being Element of a1 holds
( a2 . b1,b1 = 0 & ( b1 <> b2 implies a2 . b1,b2 = 1 ) );
existence
ex b1 being Function of [:c1,c1:], REAL st
for b2, b3 being Element of c1 holds
( b1 . b2,b2 = 0 & ( b2 <> b3 implies b1 . b2,b3 = 1 ) )
proof end;
uniqueness
for b1, b2 being Function of [:c1,c1:], REAL st ( for b3, b4 being Element of c1 holds
( b1 . b3,b3 = 0 & ( b3 <> b4 implies b1 . b3,b4 = 1 ) ) ) & ( for b3, b4 being Element of c1 holds
( b2 . b3,b3 = 0 & ( b3 <> b4 implies b2 . b3,b4 = 1 ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def11 defines discrete_dist METRIC_1:def 11 :
for b1 being set
for b2 being Function of [:b1,b1:], REAL holds
( b2 = discrete_dist b1 iff for b3, b4 being Element of b1 holds
( b2 . b3,b3 = 0 & ( b3 <> b4 implies b2 . b3,b4 = 1 ) ) );

definition
let c1 be set ;
func DiscreteSpace c1 -> strict MetrStruct equals :: METRIC_1:def 12
MetrStruct(# a1,(discrete_dist a1) #);
coherence
MetrStruct(# c1,(discrete_dist c1) #) is strict MetrStruct
;
end;

:: deftheorem Def12 defines DiscreteSpace METRIC_1:def 12 :
for b1 being set holds DiscreteSpace b1 = MetrStruct(# b1,(discrete_dist b1) #);

registration
let c1 be non empty set ;
cluster DiscreteSpace a1 -> non empty strict ;
coherence
not DiscreteSpace c1 is empty
by STRUCT_0:def 1;
end;

registration
let c1 be set ;
cluster DiscreteSpace a1 -> strict Reflexive discerning symmetric triangle ;
coherence
( DiscreteSpace c1 is Reflexive & DiscreteSpace c1 is discerning & DiscreteSpace c1 is symmetric & DiscreteSpace c1 is triangle )
proof end;
end;

definition
func real_dist -> Function of [:REAL ,REAL :], REAL means :Def13: :: METRIC_1:def 13
for b1, b2 being Element of REAL holds a1 . b1,b2 = abs (b1 - b2);
existence
ex b1 being Function of [:REAL ,REAL :], REAL st
for b2, b3 being Element of REAL holds b1 . b2,b3 = abs (b2 - b3)
proof end;
uniqueness
for b1, b2 being Function of [:REAL ,REAL :], REAL st ( for b3, b4 being Element of REAL holds b1 . b3,b4 = abs (b3 - b4) ) & ( for b3, b4 being Element of REAL holds b2 . b3,b4 = abs (b3 - b4) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def13 defines real_dist METRIC_1:def 13 :
for b1 being Function of [:REAL ,REAL :], REAL holds
( b1 = real_dist iff for b2, b3 being Element of REAL holds b1 . b2,b3 = abs (b2 - b3) );

theorem Th7: :: METRIC_1:7
canceled;

theorem Th8: :: METRIC_1:8
canceled;

theorem Th9: :: METRIC_1:9
for b1, b2 being Element of REAL holds
( real_dist . b1,b2 = 0 iff b1 = b2 )
proof end;

theorem Th10: :: METRIC_1:10
for b1, b2 being Element of REAL holds real_dist . b1,b2 = real_dist . b2,b1
proof end;

theorem Th11: :: METRIC_1:11
for b1, b2, b3 being Element of REAL holds real_dist . b1,b2 <= (real_dist . b1,b3) + (real_dist . b3,b2)
proof end;

definition
func RealSpace -> strict MetrStruct equals :: METRIC_1:def 14
MetrStruct(# REAL ,real_dist #);
coherence
MetrStruct(# REAL ,real_dist #) is strict MetrStruct
;
end;

:: deftheorem Def14 defines RealSpace METRIC_1:def 14 :
RealSpace = MetrStruct(# REAL ,real_dist #);

registration
cluster RealSpace -> non empty strict ;
coherence
not RealSpace is empty
by STRUCT_0:def 1;
end;

registration
cluster RealSpace -> non empty strict Reflexive discerning symmetric triangle ;
coherence
( RealSpace is Reflexive & RealSpace is discerning & RealSpace is symmetric & RealSpace is triangle )
proof end;
end;

definition
let c1 be MetrStruct ;
let c2 be Element of c1;
let c3 be real number ;
func Ball c2,c3 -> Subset of a1 means :Def15: :: METRIC_1:def 15
ex b1 being non empty MetrStruct ex b2 being Element of b1 st
( b1 = a1 & b2 = a2 & a4 = { b3 where B is Element of b1 : dist b2,b3 < a3 } ) if not a1 is empty
otherwise a4 is empty;
existence
( ( not c1 is empty implies ex b1 being Subset of c1ex b2 being non empty MetrStruct ex b3 being Element of b2 st
( b2 = c1 & b3 = c2 & b1 = { b4 where B is Element of b2 : dist b3,b4 < c3 } ) ) & ( c1 is empty implies ex b1 being Subset of c1 st b1 is empty ) )
proof end;
correctness
consistency
for b1 being Subset of c1 holds verum
;
uniqueness
for b1, b2 being Subset of c1 holds
( ( not c1 is empty & ex b3 being non empty MetrStruct ex b4 being Element of b3 st
( b3 = c1 & b4 = c2 & b1 = { b5 where B is Element of b3 : dist b4,b5 < c3 } ) & ex b3 being non empty MetrStruct ex b4 being Element of b3 st
( b3 = c1 & b4 = c2 & b2 = { b5 where B is Element of b3 : dist b4,b5 < c3 } ) implies b1 = b2 ) & ( c1 is empty & b1 is empty & b2 is empty implies b1 = b2 ) )
;
;
end;

:: deftheorem Def15 defines Ball METRIC_1:def 15 :
for b1 being MetrStruct
for b2 being Element of b1
for b3 being real number
for b4 being Subset of b1 holds
( ( not b1 is empty implies ( b4 = Ball b2,b3 iff ex b5 being non empty MetrStruct ex b6 being Element of b5 st
( b5 = b1 & b6 = b2 & b4 = { b7 where B is Element of b5 : dist b6,b7 < b3 } ) ) ) & ( b1 is empty implies ( b4 = Ball b2,b3 iff b4 is empty ) ) );

definition
let c1 be MetrStruct ;
let c2 be Element of c1;
let c3 be real number ;
func cl_Ball c2,c3 -> Subset of a1 means :Def16: :: METRIC_1:def 16
ex b1 being non empty MetrStruct ex b2 being Element of b1 st
( b1 = a1 & b2 = a2 & a4 = { b3 where B is Element of b1 : dist b2,b3 <= a3 } ) if not a1 is empty
otherwise a4 is empty;
existence
( ( not c1 is empty implies ex b1 being Subset of c1ex b2 being non empty MetrStruct ex b3 being Element of b2 st
( b2 = c1 & b3 = c2 & b1 = { b4 where B is Element of b2 : dist b3,b4 <= c3 } ) ) & ( c1 is empty implies ex b1 being Subset of c1 st b1 is empty ) )
proof end;
correctness
consistency
for b1 being Subset of c1 holds verum
;
uniqueness
for b1, b2 being Subset of c1 holds
( ( not c1 is empty & ex b3 being non empty MetrStruct ex b4 being Element of b3 st
( b3 = c1 & b4 = c2 & b1 = { b5 where B is Element of b3 : dist b4,b5 <= c3 } ) & ex b3 being non empty MetrStruct ex b4 being Element of b3 st
( b3 = c1 & b4 = c2 & b2 = { b5 where B is Element of b3 : dist b4,b5 <= c3 } ) implies b1 = b2 ) & ( c1 is empty & b1 is empty & b2 is empty implies b1 = b2 ) )
;
;
end;

:: deftheorem Def16 defines cl_Ball METRIC_1:def 16 :
for b1 being MetrStruct
for b2 being Element of b1
for b3 being real number
for b4 being Subset of b1 holds
( ( not b1 is empty implies ( b4 = cl_Ball b2,b3 iff ex b5 being non empty MetrStruct ex b6 being Element of b5 st
( b5 = b1 & b6 = b2 & b4 = { b7 where B is Element of b5 : dist b6,b7 <= b3 } ) ) ) & ( b1 is empty implies ( b4 = cl_Ball b2,b3 iff b4 is empty ) ) );

definition
let c1 be MetrStruct ;
let c2 be Element of c1;
let c3 be real number ;
func Sphere c2,c3 -> Subset of a1 means :Def17: :: METRIC_1:def 17
ex b1 being non empty MetrStruct ex b2 being Element of b1 st
( b1 = a1 & b2 = a2 & a4 = { b3 where B is Element of b1 : dist b2,b3 = a3 } ) if not a1 is empty
otherwise a4 is empty;
existence
( ( not c1 is empty implies ex b1 being Subset of c1ex b2 being non empty MetrStruct ex b3 being Element of b2 st
( b2 = c1 & b3 = c2 & b1 = { b4 where B is Element of b2 : dist b3,b4 = c3 } ) ) & ( c1 is empty implies ex b1 being Subset of c1 st b1 is empty ) )
proof end;
correctness
consistency
for b1 being Subset of c1 holds verum
;
uniqueness
for b1, b2 being Subset of c1 holds
( ( not c1 is empty & ex b3 being non empty MetrStruct ex b4 being Element of b3 st
( b3 = c1 & b4 = c2 & b1 = { b5 where B is Element of b3 : dist b4,b5 = c3 } ) & ex b3 being non empty MetrStruct ex b4 being Element of b3 st
( b3 = c1 & b4 = c2 & b2 = { b5 where B is Element of b3 : dist b4,b5 = c3 } ) implies b1 = b2 ) & ( c1 is empty & b1 is empty & b2 is empty implies b1 = b2 ) )
;
;
end;

:: deftheorem Def17 defines Sphere METRIC_1:def 17 :
for b1 being MetrStruct
for b2 being Element of b1
for b3 being real number
for b4 being Subset of b1 holds
( ( not b1 is empty implies ( b4 = Sphere b2,b3 iff ex b5 being non empty MetrStruct ex b6 being Element of b5 st
( b5 = b1 & b6 = b2 & b4 = { b7 where B is Element of b5 : dist b6,b7 = b3 } ) ) ) & ( b1 is empty implies ( b4 = Sphere b2,b3 iff b4 is empty ) ) );

Lemma26: for b1 being real number
for b2 being non empty MetrStruct
for b3 being Element of b2 holds Ball b3,b1 = { b4 where B is Element of b2 : dist b3,b4 < b1 }
proof end;

Lemma27: for b1 being real number
for b2 being non empty MetrStruct
for b3 being Element of b2 holds cl_Ball b3,b1 = { b4 where B is Element of b2 : dist b3,b4 <= b1 }
proof end;

Lemma28: for b1 being real number
for b2 being non empty MetrStruct
for b3 being Element of b2 holds Sphere b3,b1 = { b4 where B is Element of b2 : dist b3,b4 = b1 }
proof end;

theorem Th12: :: METRIC_1:12
for b1 being real number
for b2 being MetrStruct
for b3, b4 being Element of b2 holds
( b4 in Ball b3,b1 iff ( not b2 is empty & dist b3,b4 < b1 ) )
proof end;

theorem Th13: :: METRIC_1:13
for b1 being real number
for b2 being MetrStruct
for b3, b4 being Element of b2 holds
( b4 in cl_Ball b3,b1 iff ( not b2 is empty & dist b3,b4 <= b1 ) )
proof end;

theorem Th14: :: METRIC_1:14
for b1 being real number
for b2 being MetrStruct
for b3, b4 being Element of b2 holds
( b4 in Sphere b3,b1 iff ( not b2 is empty & dist b3,b4 = b1 ) )
proof end;

theorem Th15: :: METRIC_1:15
for b1 being real number
for b2 being MetrStruct
for b3 being Element of b2 holds Ball b3,b1 c= cl_Ball b3,b1
proof end;

theorem Th16: :: METRIC_1:16
for b1 being real number
for b2 being MetrStruct
for b3 being Element of b2 holds Sphere b3,b1 c= cl_Ball b3,b1
proof end;

theorem Th17: :: METRIC_1:17
for b1 being real number
for b2 being MetrStruct
for b3 being Element of b2 holds (Sphere b3,b1) \/ (Ball b3,b1) = cl_Ball b3,b1
proof end;

theorem Th18: :: METRIC_1:18
for b1 being real number
for b2 being non empty MetrStruct
for b3 being Element of b2 holds Ball b3,b1 = { b4 where B is Element of b2 : dist b3,b4 < b1 } by Lemma26;

theorem Th19: :: METRIC_1:19
for b1 being real number
for b2 being non empty MetrStruct
for b3 being Element of b2 holds cl_Ball b3,b1 = { b4 where B is Element of b2 : dist b3,b4 <= b1 } by Lemma27;

theorem Th20: :: METRIC_1:20
for b1 being real number
for b2 being non empty MetrStruct
for b3 being Element of b2 holds Sphere b3,b1 = { b4 where B is Element of b2 : dist b3,b4 = b1 } by Lemma28;