ϵ">]>
Module |
Remark
6. CVIČENIE Z PREDMETU ÚVOD DO DEKLARATÍVNEHO PROGRAMOVANIA http://ii.fmph.uniba.sk/cl/courses/1-AIN-505-udp/0506ls/ex/ex06.cl |
Remark
Dátum: streda 21. 3. 2006 Odporúčaná verzia CL: 5.81.16 WWW stránky: http://ii.fmph.uniba.sk/cl/courses/1-AIN-505-udp/0506ls/?lang=sk Kontakt na cvičiaceho: mailto:kluka@fmph.uniba.sk |
Remark
Dyadic regular expressions. Regular expressions are used to describe a pattern which a string can be matched against. We will restrict ourselves to dyadic strings. Regular expressions for dyadic strings are
More mathematically, we can see regular expresions as sets of strings:
We encode the regular expression in pentadic numbers by the following functions, which we call constructors . Diadické regulárne výrazy. Regulárne výrazy sa používajú na zápis vzorov , s ktorými porovnávame reťazce. Obmedzíme sa na diadické reťazce. Regulárnymi výrazmi pre diadické reťazce sú
Matematickejšie sa na regulárne výrazy môžeme pozerať ako na množiny reťazcov:
Regulárne výrazy zakódujeme do čísel v pentadickej sústave nasledujúcimi funkciami, ktoré nazývame konštruktory . |
Remark
Assignment 1. (a) Define the function which returns for every pentadic digit the number of arguments of the constructor coded by that digit. E.g., , because the digit is used to code the constructor which takes two arguments. Úloha 1. a) Definujte funkciu , ktorá pre každú pentadickú číslicu vráti počet argumentov konštruktora kódovaného touto číslicou. Napríklad , lebo číslica kóduje konštruktor , ktorý má dva argumenty. |
Remark
(b) Define the functions and (similar to functions and in exercise 5) such that if is a concatenation of codes of regular expressions, , then is the concatenation of the first codes in , and is the concatenation of the last codes in . Use the function and the discrimination b) Definujte funkcie a (podobné funkciám a v cvičení 5), aby platilo: ak je zreťazením kódov regulárnych výrazov, , tak je zreťazenie prvých kódov v a je zreťazenie posledných kódov v . Použite funkciu a diskrimináciu |
Remark
Assignment 2. Define the predicate that holds if is a code of a regular expression. Hint: Use the functions , , , and the same discrimination as in Assignment 1(b). Úloha 2. Definujte predikát , ktorý platí, ak je kódom regulárneho výrazu. Návod: Použite funkcie , , a rovnakú diskrimináciu ako v úlohe 1b). |
Remark
Assignment 3. Define the predicate with the following property: If is a pentadic concatenation of codes of regular expressions , then is true if and only if is a dyadic concatenation of some , , , ( ) and the regular expression matches the dyadic string for all . Úloha 3. Definujte predikát , ktorý má nasledujúcu vlastnosť: Ak je pentadické zreťazenie kódov regulárnych výrazov , tak je pravdivé práve vtedy, keď je diadické zreťazenie nejakých , , , ( ) a platí, že diadický reťazec vyhovuje regulárnemu výrazu pre všetky . Všimnite si, že
|
Remark
Assignment 4. Define the function that yields the greatest number less or equal to whose dyadic representation is matched by the pattern , or yields if there is no such number. Úloha 4. Definujte funkciu , ktorá vráti najväčšie číslo menšie alebo rovné číslu , ktorého diadický zápis vyhovuje regulárnemu výrazu , alebo vráti , ak niet takého čísla. |
Remark
Assignment 5. Define the following regular expressions, and check your definitions using and : Úloha 5. Definujte nasledujúce regulárne výrazy a skontrolujte vaše definície pomocou a : |
Remark
(c) which matches zero or more repetitions of 12; c) , ktorému vyhovuje nula a viac opakovaní 12; |
Remark
(d) which matches any non-empty string of twos followed by any non-empty string of ones; d) , ktorému vyhovuje hocijaký neprázdny reťazec dvojok nasledovaný hocijakým neprázdnym reťazcom jednotiek; |
Remark
(e) which matches any string starting with 22 and ending with 11 or 12; e) , ktorému vyhovuje hocijaký reťazec začínajúci 22 a končiaci 11 alebo 12; |
Remark
(f) which matches any string starting and ending with 2 and containing 111, or starting and ending with 1 and containing 222. f) , ktorému vyhovuje hocijaký reťazec začínajúci i končiaci 2 a obsahujúci 111, alebo začínajúci i končiaci 1 a obsahujúci 222. |
Remark
Assignment 7. Define the following functions operating on regular expressions and check your definitions using and : Úloha 7. Definujte nasledujúce funkcie operujúce na regulárnych výrazoch a skontrolujte vaše definície pomocou a : |
Remark
(a) which yields a regular expression matching one or more repetitions of the expression ; a) , ktorá vráti regulárny výraz, ktorému vyhovuje jedno alebo viac opakovaní výrazu ; |
Remark
(b) which yields for a regular expression matching exactly repetitions of the expression ; b) , ktorá pre vráti regulárny výraz, ktorému vyhovuje práve opakovaní výrazu ; |
Remark
(c) which yields a regular expression matching at least repetitions of the expression ; c) , ktorá pre vráti regulárny výraz, ktorému vyhovuje aspoň opakovaní výrazu ; |
Remark
(d) which yields for a regular expression matching at least one and at most repetitions of the expression ; * Try to find a solution which would yield smaller regular expressions than the straightforward . The size of such expressions grows as fast as with growing , where is the size of . Your solution should grow only as fast as . d) , ktorá pre vráti regulárny výraz, ktorému vyhovuje aspoň jedno a najviac opakovaní výrazu ; * Pokúste sa objaviť riešenie, ktoré vyrobí menšie regulárne výrazy ako priamočiare . Veľkosť takýchto výrazov rastie s rastúcim rovnako rýchlo ako , kde je veľkosť . Vaše riešenie by malo rásť len tak rýchlo ako . |
Query: |
|
Results: |
|