SLIDE 1 13th LSF A Logi al and Semanti F ramew
with Appli ations UF C, F
CE Ma r us Ramos Some Appli ations Septemb er 26th, 2018 1 / 29
SLIDE 2 Some Appli ations
the F
the Pumping Lemma fo r Context-F ree Languages Ma r us Vin ius Midena Ramos (UNIV ASF, P etrolina, PE) Jos Ca rlos Ba ela r Almeida (HASLab
TEC, Universidade do Minho, Braga, P
Nelma Mo reira (Depa rtamento de Cin ia de Computado res, F a uldade de Cin ias, P
P
Ruy J. G. B. de Queiroz (UFPE, Re ife, PE) Septemb er 26th, 2018 Ma r us Ramos Some Appli ations Septemb er 26th, 2018 2 / 29
SLIDE 3 S op e F
a substantial pa rt
language theo ry in the Co q p ro
assistant.
◮
F
is the p ro ess
writing p ro
su h that they have a p re ise meaning
a simple and w ell-dened al ulus whose rules an b e automati ally he k ed b y a ma hine;
◮
Context-free language theo ry is fundamental in the rep resentation and study
a rti ial languages, sp e ially p rogramming languages, and in the
their p ro esso rs ( ompilers and interp reters);
◮
The fo rmalization
language theo ry is a k ey to the erti ation
and p rograms, as w ell as to the development
new languages and to
fo r ertied p rogramming. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 3 / 29
SLIDE 4 Context-F ree Language Theo ry Overview
◮
P a rt
F
Language Theo ry (Chomsky Hiera r hy):
◮
Regula r Languages;
◮
Context-F ree Languages ;
◮
Context-Sensitive Languages;
◮
Re ursively Enumerable Languages.
◮
Develop ed from mid 1950s to late 1970s;
◮
Sin e then, mostly text p ro
and almost no fo rmalization;
◮
Relevant to the rep resentation, study and implementation
a rti ial languages; Ma r us Ramos Some Appli ations Septemb er 26th, 2018 4 / 29
SLIDE 5 Context-F ree Language Theo ry Steps Main results sin e 2013: 1 Closure p rop erties ( 9th LSF A 2014 ):
◮
Union;
◮
Con atenation;
◮
Kleene sta r. 2 Gramma r simpli ation ( 10th LSF A 2015 ):
◮
Elimination
empt y rules;
◮
Elimination
unit;
◮
Elimination
useless symb
◮
Elimination
ina essible symb
3 Chomsky No rmal F
4 Pumping Lemma ( JFR, 2016 ) 5 Languages that a re not
( 13th LSF A, 2018 ) Ma r us Ramos Some Appli ations Septemb er 26th, 2018 5 / 29
SLIDE 6 Basi Denitions Context-F ree Gramma r
G = (V, Σ, P, S)
, where:
◮ V
is the vo abula ry
;
◮ Σ
is the set
terminal symb
◮ N = V \ Σ
is the set
non-terminal symb
◮ P
is the set
rules α → β , with α ∈ N and β ∈ V ∗ ;
◮ S ∈ N
is the sta rt symb
Re ord fg ( non_terminal terminal : Type ): Type := { start_symbol : non_terminal ; rules : non_terminal → list (non_terminal + terminal ) → Prop ; rules_finite :
∃
n : nat ,
∃
ntl : nlist ,
∃
tl : tlist , rules_finite_def start_symbol rules n ntl tl }. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 6 / 29
SLIDE 7 Basi Denitions Context-F ree Gramma r Making sure that fg rep resents a
gramma r:
◮
General t yp es might have an innite numb er
elements;
◮
W e must he k that the rules
the gramma r a re built from nite sets
terminal and non-terminal symb
◮
W e must also he k that the set
rules is nite;
◮
The p redi ate rules_finite_def is used to mak e sure that these
a re satised fo r every gramma r in the fo rmalization, either user-dened
◮
A list
non-terminal symb
(ntl), a list
terminal symb
(tl) and an upp er b
the length
the right-hand side
the rules (n) must b e supplied. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 7 / 29
SLIDE 8 Basi Denitions Example
G = ({S′, A, B, a, b}, {a, b}, {S′ → aS′, S′ → b}, S′)
generates the language a∗b. Indu tive nt1 : Type := | S ' | A | B. Indu tive t1 : Type := | a | b . Indu tive rs1 : nt1 → list (nt1 + t1 ) → Prop := r1 : rs1 S' [ inr a; inl S '℄ | r2 : rs1 S' [ inr b℄. Definition g1 : fg nt1 t1 := {| start_symbol := S'; rules := rs1 ; rules_finite := rs1_finite |}. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 8 / 29
SLIDE 9 Basi Denitions Derivation Substitution p ro ess:
s1
derives s2 b y appli ation
zero
mo re rules: s1 ⇒∗ s2 . Indu tive derives ( non_terminal terminal : Type ) ( g : fg non_terminal terminal ) : sf → sf → Prop := | derives_refl :
∀
s : sf , derives g s s | derives_step :
∀
( s1 s2 s3 : sf )
∀
( left : non_terminal )
∀
( right : sf ), derives g s1 (s2 ++ inl left :: s3 ) → rules g left right → derives g s1 (s2 ++ right ++ s3 ) Ma r us Ramos Some Appli ations Septemb er 26th, 2018 9 / 29
SLIDE 10 Basi Denitions Derivation
◮
Predi ate generates: a derivation that b egins with the sta rt symb
the gramma r;
◮
Predi ate produ es: a derivation that b egins with the sta rt symb
the gramma r and ends with a senten e.
S ⇒ α1 ⇒
derives
- α2 ⇒ ... ⇒ αn−1
- generates
⇒ αn ⇒ ω
Ma r us Ramos Some Appli ations Septemb er 26th, 2018 10 / 29
SLIDE 11 Basi Denitions Example
S ⇒ aS ⇒ aaS ⇒ aab
Lemma produ es_g1_aab : produ es g1 [a; a; b ℄. Proof . unfold produ es . unfold generates . simpl . apply derives_step with (s2 :=[inr a; inr a℄)(left := S')(right :=[inr b℄). apply derives_step with (s2 :=[inr a℄)( left := S')( right :=[ inr a ;inl S '℄). apply derives_start with (left :=S ')( right :=[ inr a ;inl S '℄). apply r11 . apply r11 . apply r12 . Qed . Ma r us Ramos Some Appli ations Septemb er 26th, 2018 11 / 29
SLIDE 12 Basi Denitions Gramma r Equivalen e
g1 ≡ g2
if they generate the same language, that is,
∀s, (S1 ⇒∗
g1 s) ↔ (S2 ⇒∗ g2 s)
Definition g_equiv ( non_terminal1 non_terminal2 terminal : Type ) ( g1 : fg non_terminal1 terminal ) ( g2 : fg non_terminal2 terminal ): Prop :=
∀
s : list terminal , produ es g1 s ↔ produ es g2 s. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 12 / 29
SLIDE 13 Basi Denitions Context-F ree Language
◮
A language is a set
strings
a given alphab et;
◮
A
language is a language that is generated b y some
gramma r: L(G) = {w | S ⇒∗
g w}
. Definition lang (terminal : Type ):= list terminal → Prop . Definition lang_of_g (g: fg ): lang := fun w: list terminal ⇒ produ es g w. Definition lang_eq (l k: lang ) :=
∀
w, l w ↔ k w. Definition fl (terminal : Type ) ( l : lang terminal ): Prop :=
∃
non_terminal : Type ,
∃
g: fg non_terminal terminal , lang_eq l (lang_of_g g ). Ma r us Ramos Some Appli ations Septemb er 26th, 2018 13 / 29
SLIDE 14 Appli ations Obje tives
◮
Derive fo rmal p ro
that some w ell-kno wn, lassi languages, a re not
F
this, w e use the fo rmalization
the Pumping Lemma p reviously
b y the autho rs in the Co q p ro
assistant. F
ea h
these languages, w e dis uss the fo rmalization
their non
and mak e hop efully useful
ab
the p ro
p ro ess and the
y
the
fo rmal and text p ro
◮
Develop a fo rmal p ro
the fa t that the lass
the
languages is not losed under the interse tion
eration. F
that, w e follo w the lassi al p ro
that uses a
whi h in
ase is
the languages p roved not to b e
in the p revious
Ma r us Ramos Some Appli ations Septemb er 26th, 2018 14 / 29
SLIDE 15 Appli ations Pumping Lemma Let L b e a
language dened
alphab et Σ . Then there is a numb er n , dep ending
su h that fo r every senten e α ∈ L , if
|α| ≥ n ,
then all
the follo wing a re true (|w| denotes the length
the w
):
◮ ∃ u, v, w, x, y.(α = uvwxy)
;
◮ |vx| ≥ 1
;
◮ |vwx| ≤ n ; ◮ ∀i.(uviwxiy ∈ L)
A t ypi al use
the Pumping Lemma is to sho w that a given language is not
b y using the
the statement
the lemma. The info rmal p ro
p ro eeds b y
the language is assumed to b e
and this leads to a
from whi h
that the language in question an not b e
Ma r us Ramos Some Appli ations Septemb er 26th, 2018 15 / 29
SLIDE 16 Appli ations Languages Classi al languages
1 squa re: {w ∈ {a}∗ | ∃ i, |w| = i2, i ≥ 0} , 2 p rime: {w ∈ {a}∗ | |w| is a p rime numb er} , 3 anbn n: {aibici | i ≥ 0} . F
ea h:
◮
T ext p ro
◮
F
p ro
◮
Compa rison. Besides these languages, w e also dis uss: 4 anbnanbn: {anbnanbn | n ≥ 0} 5 ww: {ww | w ∈ {a, b}∗} Ma r us Ramos Some Appli ations Septemb er 26th, 2018 16 / 29
SLIDE 17 Appli ations Languages Results: 1 squa re: straightfo rw a rd; (∼ 20x expansion fa to r) 2 p rime: straightfo rw a rd; (∼ 20x expansion fa to r) 3 anbn n: mu h ha rder (why?); (∼ 100x expansion fa to r) 4 anbnanbn: mu h mu h ha rder (in omplete); (∼ 200x expansion fa to r) 5 ww: also in omplete. Let's tak e a lo
at anbn n. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 17 / 29
SLIDE 18 Appli ations Language anbn n T ext p ro
◮
Supp
that it is
and
the w
, where n is the
the Pumping Lemma;
◮ anbncn ∈
anbn n and |anbncn| ≥ n . Thus, the Pumping Lemma an b e applied;
◮ anbncn = uvwxy
fo r some u, v , w , x and y , with |uvwxy| = 3n ,
1 ≤ |vwx| ≤ n
and uviwxiy ∈ anbn n, ∀i ≥ 0 ;
◮ vwx,
due to its length limitation,
t w
kind
symb
◮
If it
kind
symb
then v and x a re also built
a single symb
and the pumping
and x will hange the numb er
a single symb
while the numb er
the
t w
un hanged. Thus, the new w
an not b elong to anbn n; Ma r us Ramos Some Appli ations Septemb er 26th, 2018 18 / 29
SLIDE 19 Appli ations Language anbn n T ext p ro
◮
If it
t w
kinds
symb
then v and x might
t w
kinds
symb
ea h. If b
kind
symb
pumping will hange the numb er
at most t w
while the third will remain un hanged. If v
t w
kinds
symb
pumping will lead to a w
where the
is not resp e ted (rst as, then bs then c s). In all ases, the new w
do es not b elong to anbn n;
◮
Hyp
is false and anbn n is not
Ma r us Ramos Some Appli ations Septemb er 26th, 2018 19 / 29
SLIDE 20 Appli ations Language anbn n F
Indu tive terminal : Type := | a | b | . Definition anbn n : lang terminal := fun ( s : list terminal ) ⇒
∃
x y z: list terminal ,
∃
i : nat , s = x ++ y ++z ∧ length x = i ∧ na x = i ∧ length y = i ∧ nb y = i ∧ length z = i ∧ n z = i. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 20 / 29
SLIDE 21 Appli ations Language anbn n F
p ro
Steps:
◮
W e have to reason ab
(either vwx ∈ a∗b∗
);
◮ v
and x might b e empt y (but not b
◮
W e
ab
- ut |v|a, |v|b, |v|c, |x|a, |x|b
and |x|c (whether ea h is
= 0
);
◮
24 ases must b e
◮
2 a re dis a rded;
◮
22 ases must b e used to sho w that uv2wx2y an not b elong to anbn n;
◮
The fo rmalization is long and tedious;
◮
Some simpli ation an b e pursued. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 21 / 29
SLIDE 22 Appli ations Language anbn n F
p ro
Ma r us Ramos Some Appli ations Septemb er 26th, 2018 22 / 29
SLIDE 23 Appli ations Interse tion Context-free languages a re not losed under interse tion: 1 F
- rmalize L1 = {anbncm | n ≥ 0 ∧ m ≥ 0}
; 2 Prove L1 is
3 F
- rmalize L2 = {ambncn | n ≥ 0 ∧ m ≥ 0}
; 4 Prove L2 is
5 F
language interse tion; 6 Prove L1 ∩ L2 = anbncn ; 7 Re all anbncn is p reviously p roved not to b e
Ma r us Ramos Some Appli ations Septemb er 26th, 2018 23 / 29
SLIDE 24 Con lusions Results Languages:
◮
squa re: straightfo rw a rd to build and easy to read;
◮
p rime: straightfo rw a rd to build and easy to read;
◮
anbn n: long and
with extensive ase analysis;
◮
anbnanbn: longer and mo re
T ak e anbnanbn , guess ab
and x and pump them;
◮
ww: simila r to anbnanbn; T ak e anbnanbn , guess ab
and x and pump them. Why? Interse tion:
◮
straightfo rw a rd to build and easy to read. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 24 / 29
SLIDE 25 Con lusions Results
◮
Size and
y in p ro
with ase analysis
◮
That is,
with languages anbn n, anbnanbn and ww;
◮
Do es not
with languages squa re and p rime and interse tion;
◮
P
reasons:
◮
(*) Pro
writing st yle (one ta ti p er line; no p ro
sea r hing ta ti );
◮
(*) P a rametrization an redu e the numb er
fun tions and lemmas;
◮
(**) Extensive ase analysis with no native supp
◮
(**) T ext p ro
hide many details that have to b e expli itly stated. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 25 / 29
SLIDE 26 Con lusions Case analysis Case analysis with lists (examples from anbn n and anbnanbn):
◮
Any string that is a substring
b elongs to a∗b∗ ;
◮
Any string with maximum length n that is a substring
b elongs to a∗b∗ | b∗c∗ ;
◮
Any string with maximum length n that is a substring
b elongs to a∗b∗ | b∗a∗ . Ma r us Ramos Some Appli ations Septemb er 26th, 2018 26 / 29
SLIDE 27 Con lusions T ext p ro
T ext p ro
hide details (examples from anbn n):
◮
due to its length limitation,
t w
kind
symb
◮
if it
kind
symb
then ... a re also built
a single symb
and the pumping
... will hange the numb er
a single symb
while the numb er
the
t w
un hanged;
◮
if it
t w
kinds
symb
then ...might
t w
kinds
symb
ea h;
◮
if b
kind
symb
pumping will hange the numb er
at most t w
while the third will remain un hanged;
◮
if ...
t w
kinds
symb
pumping will lead to a w
where the
is not resp e ted. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 27 / 29
SLIDE 28 Con lusions Con lusions P
◮
F uture supp
(new lib ra ries) fo r
ri s
strings (lists
symb
in Co q might help and simplify the fo rmalization;
◮
Mo re detailed (and thus self-explanato ry) text p ro
must b e
T
e used in undergraduate lasses as ase study . Ma r us Ramos Some Appli ations Septemb er 26th, 2018 28 / 29
SLIDE 29 Con lusions Final rema rks
◮
All s ripts a re publi ly available and an b e exe uted in Co q 8.8.1 (July 2018);
◮
Appli ation
a p reviously fo rmalized lemma, fundamental to the language lass;
◮
First kno wn fo rmal p ro
that some lassi al languages a re not
◮
Insights involving text and fo rmal p ro
◮
Helpful in tea hing fo rmal languages in a fo rmal framew
◮
A dds a new losure result to p revious results
the lass
the
languages. Ma r us Ramos Some Appli ations Septemb er 26th, 2018 29 / 29