• No se han encontrado resultados

Capítulo 3. Las Condiciones A Nivel Nacional

3.1 Apertura Económica

For a given regular expression, it is possible to derive a counting constraint, such that the count- ing constraint accepts exactly the language of multisets defined by (the permutation of) all words accepted by the regular expression.

As an example, consider the regular expression(A,B)*,C: The language of multisets defined by this regular expression is the set of all multisets with the same amount ofAs andBs and exactly oneCfor e.g. an alphabetΣ ={A, B, C}. A counting constraint for this language could be

straints. The regular expression is given in curly braces (i.e.{re}) in accordance to the notation in R2G2and for technical reasons to distinguish the root of the abstract syntax tree of (recursively defined) regular expressions. The domain of the rules isΓ, N / re 7→ C where N is a natural number variable or a natural number to be used in the counting constraint,reis the regular ex- pression,Cis the, maybe partially specified, counting constraint, andΓis a mapping of symbols as used in the regular expression to sets of natural number variables. To ease the formal handling in the rules, the mappingΓis used as a set of equations, where the equations have the symbol on the left hand side and the set of natural number variables as the sum on the right hand side. The role ofNis a bit unconventional, as it is not a variable for a natural number, it is a meta-variable for either a natural number (indeed, only the number 1 occurs) or for a natural number variable. It is hence sometimes needed to construct a natural number variable—fortunately only new vari- ables are needed, they are constructed using the symbolNnew. The rules relate one expression of the domain above the line with many expressions of the domain below the line, where usually the expressions below the line are decompositions of the expression above the line.

For a regular expression with the atoms (or symbols) a1, . . . , am, the general scheme of the

resulting counting constraint is ϕ(Xa1, . . . , Xam)

::=

∃Y11, . . . , Y1p, . . . , Ym1, . . . , Ymq.

Xa1=Y11+· · ·+Y1p∧. . .∧Xam=Ym1+· · ·+Ymp ∧ϕ(. . . , Yij, . . .)

The variables Xai are then bound to all the variables in the mappingΓ for the symbol ai.

This is formalized in the root rule (the last in the following set of rules), applied to the regular expression, the resulting counting constraint represents the language of multisets defined by the regular expression.

Atoms (or symbols) in regular expressions are at the leaf level of the rule based constraint con- struction. Indeed, the rule based construction spans a tree structure equally shaped to the abstract syntax tree of the regular expression, as there is exactly one rule for the decomposition of one ab- stract syntax tree node. So, when an atom occurs, the multiplicity of this symbol, represented by the natural number meta-variableN, has to be propagated to the mappingΓ, which is to be used in the end at root level.

(a,{. . . , N, . . .})∈Γ Γ, N / a7→ ∅

(ATOM)

For a sequence of two regular expressions, the multiplicity of the current context is passed to the two components, the partial constraints of the two parts are connected using a conjunction, the resulting mappings of the two regular part-expressions are also merged. This reflects the fact, that the multiplicity of the regular expressionrsimplies that the expression partsrandshave to occur also in the same multiplicity in a valid multiset.

Γr∪Γs, N / rs7→Cr∧Cs

Γr, N / r7→Cr Γs, N / s7→Cs

(SEQ)

For a disjunctive regular expression it’s multiplicity has to be divided between the two op- tions. This is reflected by the sumN =M+P, whereNis the multiplicity of the disjunction, and M andPare the multiplicity of the two components of the disjunction. The sum is a new part of the counting constraint. Note, thatM andPare both new variables constructed using theNnew

Γr∪Γs, N / r|s7→Cr∧Cs∧N =M +P

Γr, M =Nnew/ r7→Cr Γs, P =Nnew/ s7→Cs

(DISJ)

For an optional regular expression occurringNtimes, the optional sub-expression can at most also occurNtimes. This is expressed using a new multiplicity variableMfor the sub expression and the inequalityM ≤N.

Γ, N / r?7→C∧M ≤N

Γ, M =Nnew/ r7→C

(OPT)

The Kleene star is a bit tricky: the sub regular expressionrcould be repeated arbitrary often. It’s multiplicity is independent of the multiplicity ofr∗, the sub expression hence gets a new multiplicity variable. On the other hand, ifr∗does not occur at all in the valid word, then the sub expressionrcannot occur neither. This is reflected by the new constraint part¬(N = 0∧M 6=

N)—ifN is0thenMis also0, otherwise anything forMandNis OK.

Γ, N / r∗ 7→C∧ ¬(N = 0∧M 6=N) Γ, M =Nnew/ r7→C

(KLEENE)

The regular expression plus construct has, like the Kleene star, also to consider the two cases, that either the whole expressionr+does not occur at all in the valid word, or that it occurs. If it does not occur, then the part expression neither occurs, otherwise the sub expression at least occurs as often as the expression.

Γ, N / r+7→C∧((N >0∧M ≥N)∨(N = 0∧M = 0)) Γ, M =Nnew/ r7→C

(PLUS)

The root of a regular expression—more precisely of it’s abstract syntax tree—is used to finalize the constraint by adding the information of the symbol mapping.

The multiplicity meta-variable is set to one, as a valid word with respect to the regular ex- pression fully fits exactly once in the regular expression.

The mapping Γ is used in the previous rules to capture from all the variable expressions the multiplicities relating them to the corresponding symbol itself. The mapping set gets new members in the Atom rule and possibly alters the members in the sequence and disjunction rule (whenever two occurrences of the same symbol are represented in two mappings to be merged, the member becomes the sum of the two occurrences).

In the root rule the members of the mapping are now interpreted as sums (as which they syntactically occur), and are all added as conjunction to the constraint. All (free) right hand side variables are existentially bound, the symbols from the mapping (on the left hand side of the mapping equations) are now interpreted as variables for the multiplicity of their corresponding symbol, they are the only free variables of the constraint. Every binding of the free variables which yields a solution of the constraint, gives the Parikh mapping of multisets in the language modelled by the constraint.

{},1/{r} 7→ ∃. . . , Nij, . . . .C∧a1=N11+· · ·+N1p∧ · · · ∧am=Nm1+· · ·+Nmq {a1=N11+· · ·+N1p, . . . , am=Nm1+· · ·+Nmq},1/ r7→C

(REGEXPROOT)

7.3.1

Example of a Regular Expression Translated to a Counting Constraint

The calculus for translation of regular expressions to counting constraints will be applied to the following example expression:

• the set either contains acor ad.

• If there is nocin the set, then there is neither ab.

• Further, If there is noc(and hence there is ad) in the set, then there is at most oneacon- tained in the set.

• if there is nod(and hence there is ac), there are as manybs asas in the set.

Let’s see, what kind of counting constraint the calculus produces of the regular expression:

{},1/((a, b)∗, c)|(d, a? ) 7→ ∃O∃P∃M∃N . a=O+P∧b=P∧c=M∧d=N∧ ¬(M= 0∧M6=P)∧0≤N∧1 =M+N {a=O+P, b=P, c=M, d=N},1/((a, b)∗, c)|(d, a? ) 7→ ¬(M= 0∧M6=P)∧0≤N∧1 =M+N {a=P, b=P, c=M}, M/((a, b)∗, c) 7→ ¬(M= 0∧M6=P) {a=P, b=P}, M/(a, b)∗ 7→ ¬(M= 0∧M6=P) {a=P, b=P}, P / a, b 7→ ∅ {a=P}, P / a 7→ ∅ {b=P}, P / b 7→ ∅ {c=M}, M/ c 7→ ∅ {a=O, d=N}, N/(d, a? ) 7→0≤N {d=N}, N/ d 7→ ∅ {a=O}, N/ a? 7→0≤N {a=O}, O/ a 7→ ∅

The counting constraint is the consequence above the top line

∃O∃P∃M∃N . a=O+P∧b=P∧c=M ∧d=N∧ ¬(M = 0∧M 6=P)∧0≤N∧1 =M+N and arguably fulfills our verbal requirement.