:: LANG1 semantic presentation

definition
attr a1 is strict;
struct DTConstrStr -> 1-sorted ;
aggr DTConstrStr(# carrier, Rules #) -> DTConstrStr ;
sel Rules c1 -> Relation of the carrier of a1,the carrier of a1 * ;
end;

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

definition
attr a1 is strict;
struct GrammarStr -> DTConstrStr ;
aggr GrammarStr(# carrier, InitialSym, Rules #) -> GrammarStr ;
sel InitialSym c1 -> Element of the carrier of a1;
end;

registration
cluster non empty GrammarStr ;
existence
not for b1 being GrammarStr holds b1 is empty
proof end;
end;

definition
let G be DTConstrStr ;
mode Symbol of a1 is Element of a1;
mode String of a1 is Element of the carrier of a1 * ;
end;

definition
let D be set ;
let p be Element of D * , q be Element of D * ;
redefine func ^ as c2 ^ c3 -> Element of a1 * ;
coherence
p ^ q is Element of D *
proof end;
end;

registration
let D be set ;
cluster empty Element of a1 * ;
existence
ex b1 being Element of D * st b1 is empty
proof end;
end;

definition
let D be set ;
redefine func <*> as <*> c1 -> empty Element of a1 * ;
coherence
<*> D is empty Element of D *
by FINSEQ_1:def 11;
end;

definition
let D be non empty set ;
let d be Element of D;
redefine func <* as <*c2*> -> Element of a1 * ;
coherence
<*d*> is Element of D *
proof end;
let e be Element of D;
redefine func <* as <*c2,c3*> -> Element of a1 * ;
coherence
<*d,e*> is Element of D *
proof end;
end;

definition
let G be non empty DTConstrStr ;
let s be Symbol of G;
let n be FinSequence;
pred c2 ==> c3 means :Def1: :: LANG1:def 1
[s,n] in the Rules of G;
end;

:: deftheorem Def1 defines ==> LANG1:def 1 :
for G being non empty DTConstrStr
for s being Symbol of G
for n being FinSequence holds
( s ==> n iff [s,n] in the Rules of G );

definition
let G be non empty DTConstrStr ;
func Terminals c1 -> set equals :: LANG1:def 2
{ s where s is Symbol of G : for n being FinSequence holds not s ==> n } ;
coherence
{ s where s is Symbol of G : for n being FinSequence holds not s ==> n } is set
;
func NonTerminals c1 -> set equals :: LANG1:def 3
{ s where s is Symbol of G : ex n being FinSequence st s ==> n } ;
coherence
{ s where s is Symbol of G : ex n being FinSequence st s ==> n } is set
;
end;

:: deftheorem Def2 defines Terminals LANG1:def 2 :
for G being non empty DTConstrStr holds Terminals G = { s where s is Symbol of G : for n being FinSequence holds not s ==> n } ;

:: deftheorem Def3 defines NonTerminals LANG1:def 3 :
for G being non empty DTConstrStr holds NonTerminals G = { s where s is Symbol of G : ex n being FinSequence st s ==> n } ;

theorem Th1: :: LANG1:1
for G being non empty DTConstrStr holds (Terminals G) \/ (NonTerminals G) = the carrier of G
proof end;

definition
let G be non empty DTConstrStr ;
let n be String of G;
let m be String of G;
pred c2 ==> c3 means :: LANG1:def 4
ex n1, n2, n3 being String of G ex s being Symbol of G st
( n = (n1 ^ <*s*>) ^ n2 & m = (n1 ^ n3) ^ n2 & s ==> n3 );
end;

:: deftheorem Def4 defines ==> LANG1:def 4 :
for G being non empty DTConstrStr
for n, m being String of G holds
( n ==> m iff ex n1, n2, n3 being String of G ex s being Symbol of G st
( n = (n1 ^ <*s*>) ^ n2 & m = (n1 ^ n3) ^ n2 & s ==> n3 ) );

theorem Th2: :: LANG1:2
for G being non empty DTConstrStr
for s being Symbol of G
for n, n1, n2 being String of G st s ==> n holds
(n1 ^ <*s*>) ^ n2 ==> (n1 ^ n) ^ n2
proof end;

theorem Th3: :: LANG1:3
for G being non empty DTConstrStr
for s being Symbol of G
for n being String of G st s ==> n holds
<*s*> ==> n
proof end;

theorem Th4: :: LANG1:4
for G being non empty DTConstrStr
for s being Symbol of G
for n being String of G st <*s*> ==> n holds
s ==> n
proof end;

theorem Th5: :: LANG1:5
for G being non empty DTConstrStr
for n, n1, n2 being String of G st n1 ==> n2 holds
( n ^ n1 ==> n ^ n2 & n1 ^ n ==> n2 ^ n )
proof end;

definition
let G be non empty DTConstrStr ;
let n be String of G;
let m be String of G;
pred c3 is_derivable_from c2 means :Def5: :: LANG1:def 5
ex p being FinSequence st
( len p >= 1 & p . 1 = n & p . (len p) = m & ( for i being Element of NAT st i >= 1 & i < len p holds
ex a, b being String of G st
( p . i = a & p . (i + 1) = b & a ==> b ) ) );
end;

:: deftheorem Def5 defines is_derivable_from LANG1:def 5 :
for G being non empty DTConstrStr
for n, m being String of G holds
( m is_derivable_from n iff ex p being FinSequence st
( len p >= 1 & p . 1 = n & p . (len p) = m & ( for i being Element of NAT st i >= 1 & i < len p holds
ex a, b being String of G st
( p . i = a & p . (i + 1) = b & a ==> b ) ) ) );

theorem Th6: :: LANG1:6
for G being non empty DTConstrStr
for n being String of G holds n is_derivable_from n
proof end;

theorem Th7: :: LANG1:7
for G being non empty DTConstrStr
for n, m being String of G st n ==> m holds
m is_derivable_from n
proof end;

theorem Th8: :: LANG1:8
for G being non empty DTConstrStr
for n1, n2, n3 being String of G st n1 is_derivable_from n2 & n2 is_derivable_from n3 holds
n1 is_derivable_from n3
proof end;

definition
let G be non empty GrammarStr ;
func Lang c1 -> set equals :: LANG1:def 6
{ a where a is Element of the carrier of G * : ( rng a c= Terminals G & a is_derivable_from <*the InitialSym of G*> ) } ;
coherence
{ a where a is Element of the carrier of G * : ( rng a c= Terminals G & a is_derivable_from <*the InitialSym of G*> ) } is set
;
end;

:: deftheorem Def6 defines Lang LANG1:def 6 :
for G being non empty GrammarStr holds Lang G = { a where a is Element of the carrier of G * : ( rng a c= Terminals G & a is_derivable_from <*the InitialSym of G*> ) } ;

theorem Th9: :: LANG1:9
for G being non empty GrammarStr
for n being String of G holds
( n in Lang G iff ( rng n c= Terminals G & n is_derivable_from <*the InitialSym of G*> ) )
proof end;

definition
let D be non empty set , E be non empty set ;
let a be Element of [:D,E:];
redefine func { as {c3} -> Relation of a1,a2;
coherence
{a} is Relation of D,E
proof end;
let b be Element of [:D,E:];
redefine func { as {c3,c4} -> Relation of a1,a2;
coherence
{a,b} is Relation of D,E
proof end;
end;

definition
let a be set ;
func EmptyGrammar c1 -> strict GrammarStr means :Def7: :: LANG1:def 7
( the carrier of it = {a} & the Rules of it = {[a,{} ]} );
existence
ex b1 being strict GrammarStr st
( the carrier of b1 = {a} & the Rules of b1 = {[a,{} ]} )
proof end;
uniqueness
for b1, b2 being strict GrammarStr st the carrier of b1 = {a} & the Rules of b1 = {[a,{} ]} & the carrier of b2 = {a} & the Rules of b2 = {[a,{} ]} holds
b1 = b2
proof end;
let b be set ;
func SingleGrammar c1,c2 -> strict GrammarStr means :Def8: :: LANG1:def 8
( the carrier of it = {a,b} & the InitialSym of it = a & the Rules of it = {[a,<*b*>]} );
existence
ex b1 being strict GrammarStr st
( the carrier of b1 = {a,b} & the InitialSym of b1 = a & the Rules of b1 = {[a,<*b*>]} )
proof end;
uniqueness
for b1, b2 being strict GrammarStr st the carrier of b1 = {a,b} & the InitialSym of b1 = a & the Rules of b1 = {[a,<*b*>]} & the carrier of b2 = {a,b} & the InitialSym of b2 = a & the Rules of b2 = {[a,<*b*>]} holds
b1 = b2
;
func IterGrammar c1,c2 -> strict GrammarStr means :Def9: :: LANG1:def 9
( the carrier of it = {a,b} & the InitialSym of it = a & the Rules of it = {[a,<*b,a*>],[a,{} ]} );
existence
ex b1 being strict GrammarStr st
( the carrier of b1 = {a,b} & the InitialSym of b1 = a & the Rules of b1 = {[a,<*b,a*>],[a,{} ]} )
proof end;
uniqueness
for b1, b2 being strict GrammarStr st the carrier of b1 = {a,b} & the InitialSym of b1 = a & the Rules of b1 = {[a,<*b,a*>],[a,{} ]} & the carrier of b2 = {a,b} & the InitialSym of b2 = a & the Rules of b2 = {[a,<*b,a*>],[a,{} ]} holds
b1 = b2
;
end;

:: deftheorem Def7 defines EmptyGrammar LANG1:def 7 :
for a being set
for b2 being strict GrammarStr holds
( b2 = EmptyGrammar a iff ( the carrier of b2 = {a} & the Rules of b2 = {[a,{} ]} ) );

:: deftheorem Def8 defines SingleGrammar LANG1:def 8 :
for a, b being set
for b3 being strict GrammarStr holds
( b3 = SingleGrammar a,b iff ( the carrier of b3 = {a,b} & the InitialSym of b3 = a & the Rules of b3 = {[a,<*b*>]} ) );

:: deftheorem Def9 defines IterGrammar LANG1:def 9 :
for a, b being set
for b3 being strict GrammarStr holds
( b3 = IterGrammar a,b iff ( the carrier of b3 = {a,b} & the InitialSym of b3 = a & the Rules of b3 = {[a,<*b,a*>],[a,{} ]} ) );

registration
let a be set ;
cluster EmptyGrammar a1 -> non empty strict ;
coherence
not EmptyGrammar a is empty
proof end;
let b be set ;
cluster SingleGrammar a1,a2 -> non empty strict ;
coherence
not SingleGrammar a,b is empty
proof end;
cluster IterGrammar a1,a2 -> non empty strict ;
coherence
not IterGrammar a,b is empty
proof end;
end;

definition
let D be non empty set ;
func TotalGrammar c1 -> strict GrammarStr means :Def10: :: LANG1:def 10
( the carrier of it = D \/ {D} & the InitialSym of it = D & the Rules of it = { [D,<*d,D*>] where d is Element of D : d = d } \/ {[D,{} ]} );
existence
ex b1 being strict GrammarStr st
( the carrier of b1 = D \/ {D} & the InitialSym of b1 = D & the Rules of b1 = { [D,<*d,D*>] where d is Element of D : d = d } \/ {[D,{} ]} )
proof end;
uniqueness
for b1, b2 being strict GrammarStr st the carrier of b1 = D \/ {D} & the InitialSym of b1 = D & the Rules of b1 = { [D,<*d,D*>] where d is Element of D : d = d } \/ {[D,{} ]} & the carrier of b2 = D \/ {D} & the InitialSym of b2 = D & the Rules of b2 = { [D,<*d,D*>] where d is Element of D : d = d } \/ {[D,{} ]} holds
b1 = b2
;
end;

:: deftheorem Def10 defines TotalGrammar LANG1:def 10 :
for D being non empty set
for b2 being strict GrammarStr holds
( b2 = TotalGrammar D iff ( the carrier of b2 = D \/ {D} & the InitialSym of b2 = D & the Rules of b2 = { [D,<*d,D*>] where d is Element of D : d = d } \/ {[D,{} ]} ) );

registration
let D be non empty set ;
cluster TotalGrammar a1 -> non empty strict ;
coherence
not TotalGrammar D is empty
proof end;
end;

theorem Th10: :: LANG1:10
for a being set holds Terminals (EmptyGrammar a) = {}
proof end;

theorem Th11: :: LANG1:11
for a being set holds Lang (EmptyGrammar a) = {{} }
proof end;

theorem Th12: :: LANG1:12
for a, b being set st a <> b holds
Terminals (SingleGrammar a,b) = {b}
proof end;

theorem Th13: :: LANG1:13
for a, b being set st a <> b holds
Lang (SingleGrammar a,b) = {<*b*>}
proof end;

theorem Th14: :: LANG1:14
for a, b being set st a <> b holds
Terminals (IterGrammar a,b) = {b}
proof end;

theorem Th15: :: LANG1:15
for a, b being set st a <> b holds
Lang (IterGrammar a,b) = {b} *
proof end;

theorem Th16: :: LANG1:16
for D being non empty set holds Terminals (TotalGrammar D) = D
proof end;

theorem Th17: :: LANG1:17
for D being non empty set holds Lang (TotalGrammar D) = D *
proof end;

definition
let IT be non empty GrammarStr ;
attr a1 is efective means :Def11: :: LANG1:def 11
( not Lang IT is empty & the InitialSym of IT in NonTerminals IT & ( for s being Symbol of IT st s in Terminals IT holds
ex p being String of IT st
( p in Lang IT & s in rng p ) ) );
end;

:: deftheorem Def11 defines efective LANG1:def 11 :
for IT being non empty GrammarStr holds
( IT is efective iff ( not Lang IT is empty & the InitialSym of IT in NonTerminals IT & ( for s being Symbol of IT st s in Terminals IT holds
ex p being String of IT st
( p in Lang IT & s in rng p ) ) ) );

definition
let IT be GrammarStr ;
attr a1 is finite means :: LANG1:def 12
the Rules of IT is finite;
end;

:: deftheorem Def12 defines finite LANG1:def 12 :
for IT being GrammarStr holds
( IT is finite iff the Rules of IT is finite );

registration
cluster non empty efective finite GrammarStr ;
existence
ex b1 being non empty GrammarStr st
( b1 is efective & b1 is finite )
proof end;
end;

definition
let G be non empty efective GrammarStr ;
redefine func NonTerminals as NonTerminals c1 -> non empty Subset of a1;
coherence
NonTerminals G is non empty Subset of G
proof end;
end;

definition
let X be non empty set , Y be non empty set ;
let p be FinSequence of X;
let f be Function of X,Y;
redefine func * as c4 * c3 -> Element of a2 * ;
coherence
p * f is Element of Y *
proof end;
end;

definition
let X be non empty set , Y be non empty set ;
let f be Function of X,Y;
canceled;
func c3 * -> Function of a1 * ,a2 * means :: LANG1:def 14
for p being Element of X * holds it . p = f * p;
existence
ex b1 being Function of X * ,Y * st
for p being Element of X * holds b1 . p = f * p
proof end;
uniqueness
for b1, b2 being Function of X * ,Y * st ( for p being Element of X * holds b1 . p = f * p ) & ( for p being Element of X * holds b2 . p = f * p ) holds
b1 = b2
proof end;
end;

:: deftheorem Def13 LANG1:def 13 :
canceled;

:: deftheorem Def14 defines * LANG1:def 14 :
for X, Y being non empty set
for f being Function of X,Y
for b4 being Function of X * ,Y * holds
( b4 = f * iff for p being Element of X * holds b4 . p = f * p );

theorem Th18: :: LANG1:18
for R being Relation holds R c= R [*]
proof end;

definition
let X be non empty set ;
let R be Relation of X;
redefine func [*] as c2 [*] -> Relation of a1;
coherence
R [*] is Relation of X
proof end;
end;

definition
let G be non empty GrammarStr ;
let X be non empty set ;
let f be Function of the carrier of G,X;
func c1 . c3 -> strict GrammarStr equals :: LANG1:def 15
GrammarStr(# X,(f . the InitialSym of G),(((f ~ ) * the Rules of G) * (f * )) #);
correctness
coherence
GrammarStr(# X,(f . the InitialSym of G),(((f ~ ) * the Rules of G) * (f * )) #) is strict GrammarStr
;
;
end;

:: deftheorem Def15 defines . LANG1:def 15 :
for G being non empty GrammarStr
for X being non empty set
for f being Function of the carrier of G,X holds G . f = GrammarStr(# X,(f . the InitialSym of G),(((f ~ ) * the Rules of G) * (f * )) #);