:: 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 c1 be DTConstrStr ;
mode Symbol of a1 is Element of a1;
mode String of a1 is Element of the carrier of a1 * ;
end;

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

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

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

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

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

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

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

:: deftheorem Def2 defines Terminals LANG1:def 2 :
for b1 being non empty DTConstrStr holds Terminals b1 = { b2 where B is Symbol of b1 : for b1 being FinSequence holds not b2 ==> b3 } ;

:: deftheorem Def3 defines NonTerminals LANG1:def 3 :
for b1 being non empty DTConstrStr holds NonTerminals b1 = { b2 where B is Symbol of b1 : ex b1 being FinSequence st b2 ==> b3 } ;

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

definition
let c1 be non empty DTConstrStr ;
let c2, c3 be String of c1;
pred c2 ==> c3 means :: LANG1:def 4
ex b1, b2, b3 being String of a1ex b4 being Symbol of a1 st
( a2 = (b1 ^ <*b4*>) ^ b2 & a3 = (b1 ^ b3) ^ b2 & b4 ==> b3 );
end;

:: deftheorem Def4 defines ==> LANG1:def 4 :
for b1 being non empty DTConstrStr
for b2, b3 being String of b1 holds
( b2 ==> b3 iff ex b4, b5, b6 being String of b1ex b7 being Symbol of b1 st
( b2 = (b4 ^ <*b7*>) ^ b5 & b3 = (b4 ^ b6) ^ b5 & b7 ==> b6 ) );

theorem Th2: :: LANG1:2
for b1 being non empty DTConstrStr
for b2 being Symbol of b1
for b3, b4, b5 being String of b1 st b2 ==> b3 holds
(b4 ^ <*b2*>) ^ b5 ==> (b4 ^ b3) ^ b5
proof end;

theorem Th3: :: LANG1:3
for b1 being non empty DTConstrStr
for b2 being Symbol of b1
for b3 being String of b1 st b2 ==> b3 holds
<*b2*> ==> b3
proof end;

theorem Th4: :: LANG1:4
for b1 being non empty DTConstrStr
for b2 being Symbol of b1
for b3 being String of b1 st <*b2*> ==> b3 holds
b2 ==> b3
proof end;

theorem Th5: :: LANG1:5
for b1 being non empty DTConstrStr
for b2, b3, b4 being String of b1 st b3 ==> b4 holds
( b2 ^ b3 ==> b2 ^ b4 & b3 ^ b2 ==> b4 ^ b2 )
proof end;

definition
let c1 be non empty DTConstrStr ;
let c2, c3 be String of c1;
pred c3 is_derivable_from c2 means :Def5: :: LANG1:def 5
ex b1 being FinSequence st
( len b1 >= 1 & b1 . 1 = a2 & b1 . (len b1) = a3 & ( for b2 being Nat st b2 >= 1 & b2 < len b1 holds
ex b3, b4 being String of a1 st
( b1 . b2 = b3 & b1 . (b2 + 1) = b4 & b3 ==> b4 ) ) );
end;

:: deftheorem Def5 defines is_derivable_from LANG1:def 5 :
for b1 being non empty DTConstrStr
for b2, b3 being String of b1 holds
( b3 is_derivable_from b2 iff ex b4 being FinSequence st
( len b4 >= 1 & b4 . 1 = b2 & b4 . (len b4) = b3 & ( for b5 being Nat st b5 >= 1 & b5 < len b4 holds
ex b6, b7 being String of b1 st
( b4 . b5 = b6 & b4 . (b5 + 1) = b7 & b6 ==> b7 ) ) ) );

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

theorem Th7: :: LANG1:7
for b1 being non empty DTConstrStr
for b2, b3 being String of b1 st b2 ==> b3 holds
b3 is_derivable_from b2
proof end;

theorem Th8: :: LANG1:8
for b1 being non empty DTConstrStr
for b2, b3, b4 being String of b1 st b2 is_derivable_from b3 & b3 is_derivable_from b4 holds
b2 is_derivable_from b4
proof end;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

:: deftheorem Def12 defines finite LANG1:def 12 :
for b1 being GrammarStr holds
( b1 is finite iff the Rules of b1 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 c1 be non empty efective GrammarStr ;
redefine func NonTerminals as NonTerminals c1 -> non empty Subset of a1;
coherence
NonTerminals c1 is non empty Subset of c1
proof end;
end;

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

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

:: deftheorem Def13 LANG1:def 13 :
canceled;

:: deftheorem Def14 defines * LANG1:def 14 :
for b1, b2 being non empty set
for b3 being Function of b1,b2
for b4 being Function of b1 * ,b2 * holds
( b4 = b3 * iff for b5 being Element of b1 * holds b4 . b5 = b3 * b5 );

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

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

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

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