Foundations of software analysis - analysis

i have question about Mathematical Foundations
Let (D, ⊑) be a partial order, where D is a finite, non-empty set. An anti-chain is a set of elements, where any distinct two elements are incomparable. Prove that the minimum number ofanti-chains Si , for 1 ≤ i ≤ n, that are required to cover D, i.e., D = ∪ Si ( i= 1 to n ) , is equal to the length of the longest chain in D.
i have any idea about it.

Related

How to declare/use Arrays and Quantifiers in Z3Py?

I'm new to Z3py and I found an exercise where it would ask to check if some verification conditions were true. Up to this moment, the exercises I've done were basically to transform simple propositional formulas into z3py clauses, something like:
Propositional Formula would be:
(n>=4) -> (x = y +2)
Which would become in Z3Py:
n, x, y = Ints('n x y')
s.add(Implies(n>=5, x == y+3))
The conditions I'm presented now, introduce Arrays and Quantifiers and after spending hours trying to figure it out on the documentation around, I'm still not able to get it properly done.
For example, how would I do the same process above but with the following conditions:
n ≥ 1 ∧ i = 1 ∧ m = A[0]
i <= n ∧ ∀j. 0 ≤ j < i → m ≥ A[j]
A little snippet of what I think that is correctly done:
i, n = Ints('i n')
s.add(And(n>=1, i == 1, ???)
s.add(And(i<=n,Implies(???))
How should I replace the ??? so that the conditions would be correctly transformed into Z3Py?
Solution:
- The constraint
n ≥ 1 ∧ i = 1 ∧ m = A[0]
would become in Z3Py:
A = Array('A', IntSort(), IntSort()) //Array declaration
i, n, m, j = Ints('i n m j') //Ints declaration for both constraints
And(n>=1, i==1, m==A[0])
- The constraint
i <= n ∧ ∀j. 0 ≤ j < i → m ≥ A[j]
would become:
And(i<=n,ForAll(j,Implies(And(j>=0,j<i),m>=A[j])))
Your questions is quite ambiguous. Note that you've the constraints:
n ≥ 1 ∧ i = 1
and then
i <= n
but that consequent is already implied by the first, and hence is redundant. Meaning, if you add them both to the solver like you did with your s.add lines, then it won't really mean much of anything at all.
I'm guessing these two lines actually arise in different "subparts" of the problem, i.e., they aren't used together for the same verification goal. And, making an educated guess, you're trying to say something about the maximum element of an array; where i is some sort of a loop-counter. The first line is what happens before the loop starts, and the second is the invariant the loop-body ensures. If this is the case, you should be explicit about that.
Assuming this is the case, then these sorts of problems are usually modeled on the "body" of that loop, i.e., you need to show us exactly what sort of a "program" you're dealing with. That is, these constraints will only make sense in the presence of some sort of a transformation of your program variables.

Can all context free grammars be converted to NFA/DFA?

I've seen this post about how to convert context free grammar to a DFA:
Automata theory : Conversion of a Context free grammar to a DFA
However, just wondering can all context free grammars be converted to DFA/NFA? What about context free grammars that cannot be expressed as a regular expression? Ex. S->(S) | ()
Thanks!
Only regular languages can be converted to a DFA, and not all CFGs represent regular languages, including the one in the question.
So the answer is "no".
NFAs are not more expressive than DFAs, so the above statement would still be true if you replaced DFA with NFA
A CFG represents a regular language if it is right- or left-linear. But the mere fact that a CFG is not left- or right-linear proves nothing. For example, S→a | a S a happens to generate the same language as S→a | S a a.
Yes ... if the F in "DFA" is replaced by I to get "DIA", but no ... for DFA, itself; and I will show how this works for your example at the end. In fact, all languages have DIA's whose state diagrams reside on a single Universal State Diagram as sub-diagrams thereof.
Consider your example, but rewrite it as S → u S v, S → w. This grammar, like all grammars, is algebraically a system of inequations over a certain partially ordered algebra. In particular, it can be rewritten as
S ⊇ {u}S{v}, S ⊇ {w},
or equivalently as
S ⊇ {u}S{v} ∪ {w}.
The object identified by the grammar is the least solution to the system. Since the system is a fixed point system S ⊇ f(S) = {u}S{v} ∪ {w}, then the least solution may also be described as the least fixed point solution and it is denoted μx f(x) = μx({u}x{v} ∪ {w}).
The ordering relation, for this algebra here, is subset ordering y ⊆ x ⇔ x ⊇ y. The operations include a product AB ≡ { ab: a ∈ A, b ∈ B }, defined element-wise (where, component-wise, the product is word concatenation, with ab being the concatenation of a and b). The product has {1} as an identity, where 1 denotes the empty word. Both word concatenation and product satisfy the fundamental properties
(xy)z = x(yz) [Associativity]
and
xe = x = ex [Identity property]
with the respective identities e = 1 (for concatenation) or e = {1} (for set product). The algebra is called a Monoid.
The simplest and most direct monoid formed from the elements X = {u,v,w} is the Free Monoid X* = {u,v,w}*, which is equivalently described as the set of all words of finite length (including the empty word, 1, of length 0) formed from u, v and w. It is possible to frame the question in terms of more general monoids, but (as the literature usually does) I will restrict it to free monoids.
The family of languages over X is one and the same as the family 𝔓M of subsets A ⊆ M of the monoid M = X*; the defining condition being A ∈ 𝔓M ⇔ A ⊆ M. Other distinguished subfamilies exist, such as the families ℜM ⊆ ℭM ⊆ 𝔗M ⊆ 𝔓M, respectively, of rational, context-free and Turing (or recursively enumerable) languages. The second of these ℭM, which is what your question is concerned with, are given by context-free grammars and are identified as the least fixed point solutions to the corresponding fixed point system of inequations.
Over 𝔓M, one can define the left-quotient operation v\A = { w ∈ M: vw ∈ A }, for each word v ∈ M and subset A ∈ 𝔓M. Because M = X* is a free monoid, it can be decomposed uniquely into left-quotients on the individual elements of X, by the properties 1\A = A, and (vw)\A = w\(v\A).
Correspondingly, one can define a state transition on each x ∈ X by x: A → x\A, treating each subset A ∈ 𝔓M as a state. Together, 𝔓M comprises the state set of the Universal State Diagram over M. Because M = X* is a free monoid, every element of M is either of the form xw for some x ∈ X and w ∈ X*, or is the empty word 1. The decomposition is unique: xw ≠ 1 for any x ∈ X or w ∈ X* and xw = x'w' for x, x' ∈ X and w, w' ∈ X*, only if x = x' and w = w'. Therefore, every A ∈ 𝔓M decomposes uniquely into a partition in a manner analogous to Taylor's Theorem as
A = A₀ ∪ ⋃_{x∈X} {x} x\A.
where A₀ ≡ A ∩ {1} is either {1} if 1 ∈ A or is ∅ if 1 ∉ A. The states for which A₀ = {1} may be regarded as the Final States in the Universal State Diagram.
The analogy to Taylor's Theorem is not too far-removed, since the left-quotient satisfies an analogue of the Product Rule
x\(AB) = (x\A) B ∪ A₀ (x\B)
so it is also denoted as a partial derivative x\A = ∂A/∂x: the Brzozowski Derivative, so that the decomposition rule could just as well be written as:
A = A₀ ∪ ⋃_{x∈X} {x} ∂A/∂x.
What you actually have is an infinite fixed-point system of inequations
A ⊇ A₀ ∪ ⋃_{x∈X} {x} ∂A/∂x for all A ∈ 𝔓M,
with variables A ∈ 𝔓M ranging over all of 𝔓M, whose right-hand sides are all right-linear in the variables. The sets, themselves, are the least fixed point solution to their own system (and to all closed subsystems of the universal system that contain that set as a variable).
Choosing different states as start states yields the different DIA's contained within it. Every minimal DIA (and every minimal DFA) of every language over X is contained in it.
In particular, in this diagram, you can consider the largest subdiagram accessible from a specific state A ∈ 𝔓M. All the states that can be accessed from A are left-quotients by words in M. So, together they comprise a family δA ≡ { v\A: v ∈ M }. The subdiagram consisting only of these states gives you the minimal DIA for the language A, where A, itself, is treated as the start state of the DIA.
If δA is finite, then the I is an F and it's actually a DFA - and that's what you're looking for. Which states in 𝔓M have DIA that are actually DFA's? The regular ones - the ones in the subfamily ℜM ⊆ 𝔓M. This is the case when M = X* is a free monoid. I'm not totally sure if this can also be proven for non-free monoids (like X* × Y*, whose rational subsets ℜ(X* × Y*) are one and the same as what are known as rational transductions) ... because of the reliance on the Taylor's Formula decomposition. There is still something like a Taylor's Theorem, but the decompositions are not necessarily partitions or unique, any longer.
For larger subfamilies of 𝔓M, the DIA are necessarily infinite; but their transitions may possess a sufficient degree of symmetry to allow both the states and transition rules to be wrapped up more succinctly. Correspondingly, one can distinguish different families of DIA by what symmetry properties they possess.
For your example, X = {u,v,w} and M = {u,v,w}*. The subset identified by your grammar is S = {uⁿ w vⁿ: n = 0, 1, 2, ...}. We can define the following sets
S(n) = S {vⁿ}, T(n) = {vⁿ}, for n = 0, 1, 2, ...
The sub-diagram of states accessible from S consists of all the states
δS = { S(n): n = 0, 1, 2, ... } ∪ { T(n): n = 0, 1, 2, ... } ∪ { ∅ }
The state transitions are the following
u: S(n) → S(n+1)
v: T(n+1) → T(n)
w: S(n) → T(n)
with x: A → ∅ in all other cases for x ∈ {u,v,w} and A ∈ δS. The sole final state is T(0).
As you can see, the DIA is infinite and is not a DFA at all. If you were to draw out the diagram, you would see an infinite ladder with S = S(0) being the start state T(0) = {1} the final state, with all the u transitions climbing up a rung, all the v transitions climbing down a rung, and the w transitions crossing over on a rung.
The symmetry is captured by factoring the state set into
δS = {S,T}×{0,1,2,3,⋯} ∪ {∅}
with S(n) rewritten as (S,n) and T(n) as (T,n). This includes a finite set of states Q = {S,T} for a finite state "control" and a set of states D = {0,1,2,3,⋯} for a "device"; as well as the empty set ∅ for the fail state. That device is none other than a counter, and this DIA is just a one-counter automaton in disguise.
All of the classical automata models posed in the literature have a similar form, when expressed as DIA. They contain a state set Q×D ∪ {∅} that includes a finite set Q for the "finite state control" and a (generally infinite) state set D for the device, along with the fail state ∅. The restrictions or constraints on the device correspond to what types of symmetries are contained in the underlying DIA. A deterministic PDA, with two stack symbols {a,b} for instance, has a device state set D = {a,b}* (consisting of all stack words), and an underlying DIA that has the form of an infinite binary tree with copies of Q residing at each node.
You can best see this by writing out and graphing the DIA for the Dyck language, which is given by the grammar D₂ → b D₂ d D₂, D₂ → p D₂ q D₂, D₂ → 1 as a language over X = {b,d,p,q} and subset of M = X* = {b,d,p,q}*; i.e. as the least-fixed point D₂ = μx ({b}x{d}x ∪ {p}x{q}x ∪ {1}).
Every subset in A ⊆ ℭM can be expressed in terms of a subset in A' ⊆ ℜM[b,d,p,q] of the free extension of the monoid M by indeterminates {b,d,p,q}, by carrying out insertions of {b,d,p,q} in suitable places in A, such that the result upon applying the identities {bd} = {1} = {pq}, {bq} = ∅ = {pd}, and xy = yx for x ∈ M and y ∈ {b,d,p,q} will yield A, itself, from A'.
This result (known, but unpublished since the 1990's and published only in 2022) is the algebraic form of the Chomsky-Schützenberger Theorem and is true for all monoids M. For instance, it holds for the non-free monoid M = X* × Y*, where the corresponding family ℭ(X* × Y*) comprise the push-down transductions from X to Y (or "simple syntax directed translations"; aka yacc-like grammars).
So, there is also something like a DFA even for these classes of DIA; provided you include transition arrows for {b,d,p,q}. For your example, A = μx({u}x{v} ∪ {w}), you have A' = {b}{up,qv,w}*{d} and you can easily write down the corresponding DFA. That automaton is just the one-counter machine, itself, with "b" interpreted as "start up at count 0", "d" as "check for count 0 and finish", "p" as "add one to the count" and "q" as "check for count greater than 0 and subtract 1". With respect to the algebraic rules given for {b,d,p,q}, A' is not just a representation of A, it is actually is A: A' = A.

Pumping Lemma Assistance

I recently had an assignment where I was asked to use pumping lemma to show that a language was not regular, and unfortunately got the wrong answer.
The language to prove is non-regular is as follows:
L = {ai bj ck: i = j or j = k}
The definition of a pumping lemma that I was given is as follows:
opponent picks m
I want to pick w to contradict the pumping lemma. Use m to pick a string w ∈ L where |w| ≥ m
opponent picks a decomposition of w subject to constraints.
I try to pick an i so that the pumped string wi ∉ L. If found, L is not regular
This subject has proven to be very difficult for me to understand and I feel like a complete airhead because of it, so a detailed explanation as to how I would properly apply a pumping lemma would be appreciated.
Intuitively, the pumping lemma says that long enough words (the length depends only on the language L) in a regular language L must contain a section (of length > 0) which can be repeated as often as desired. Repeating that section ('pumping' the original word) any number of time results in some longer words which are also in the language L.
The minimal length for the word is the m in the first step of the above definition; the number of times the section is repeated is the i in the 4th step of the above definition.
The pumping lemma is usually used to show that a language L is not regular. It is a proof by contradiction: assume that L is regular and thus the pumping lemma for regular languages is true for L. Then pick a word w which is in L of sufficient length* and show that regardless of how it is decomposed* some pumped word is not in the language. This contradicts the pumping lemma - which we know to be true. Thus our assumption that the language is regular was wrong and thus the language is not regular. The parts marked with an * cannot be chosen to make things easy - that's why in steps 1 and 3 the 'opponent' selects them.
The word w is rewritten as w = x y z, where | y | > 0 and |x y| <= m. Both x and z may be of length 0.
The usual approach is to pick xy to be a string consisting of the same letter such that having more of that same letter (after the pumping) leads to a word not in L.
No restrictions are specified for the i or the k in the language L in the post, so assuming that i = 0 is allowed, a suitable word might be b^m c^m (that is m bs followed by m cs). Now whatever decomposition the opponent might select, the y will always consist of some bs. Repeating those bs leads to a word with more bs than cs and no as, and thus i != j and j!= k and the word is not in the language.

automata: using only Equivalence class to proove regularity

I have tried to go about this problem in several ways, and looked in several places with no answer. the question is as follow:
[Question]
Given two regular languages (may be referred to as finitely described languages ,idk) L1 and L2, we define a new language as such:
L = {w1w2| there are two words, x,y such that : xw1 is in L1, w2y is in L2}
I am supposed to use to show that L is regular, however I have the following restrictions:
I must use Equivalence class, and no other way
I cannot use Rank(L), as in show a limit to the number of equivalence class, instead I must show them
I may use the Closure properties that all regular languages hold
I am not expecting a full proof (though that would be appreciated) but an explanation to how to go about such a thing.
thanks in advance.
L = {w1w2| there are two words, x,y such that : xw1 is in L1, w2y is in L2} is regular if L1 and L2 are regular languages.
Lsuff = { w1 | xw1 ∈ L1 }
Lpref = { w2 | w2y ∈ L2 }
And,
L = LsuffLpref
We can easily proof by construction Finite Automata for L.
Suppose Finite Automata(FA) for L1 is M1 and FA for L2 is M2.
[SOLUTION]
Non-Deterministic Finite Automata(NFA) for L can be drawn by introducing NULL-transition (^-edge) form every state in M1 to every state in M2. then NFA can be converted into DFA.
e.g.
L1 = {ab ,ac} and L2 = {12, 13}
L = {ab, ac, 12, 13, a12, a2, ab12, ab2, a13, a3, ab13, ab3, ............}
Note: w1 and w2 can be NULL
M1 =is consist of Q = {q0,q1,qf} with edges:
q0 ---a----->q1,
q1 ---b/c--->qf
Similarly :
M2 =is consist of Q = {p0,p1,pf} with edges:
p0 ---1----->p1,
p1 ---2/3--->pf
Now, NFA for L called M will be consist of Q = {q0,q1,qf, p0,p1,pf} Where Final state of M is pf and edges are:
q0 ---a----->q1,
q1 ---b/c--->qf,
p0 ---1----->p1,
p1 ---2/3--->pf,
q0 ----^----> p0,
q1 ----^----> p0,
qf ----^----> p0,
q0 ----^----> p1,
q1 ----^----> p1,
qf ----^----> p1,
q0 ----^----> pf,
q1 ----^----> pf,
qf ----^----> pf
^ means NULL-Transition.
Now, A NFA can easily convert into DFA.(I leave it for you)
[ANSWER]
DFA for L is possible hence L is Regular Language.
I will highly encourage you to draw DFA/NFA figures, then concept will be clear.>
Note
I am writing this answer, because I believe that the current available doesn't really satisfy the post requirements, i.e.
I must use Equivalence class, and no other way
Answer
A more direct and simple approach is to not construct a DFA/NFA because of time reasons, but to just check if #EquivalenceClasses < ∞ holds. Specifically, you would have the following ones here:
[w1] = {all w1 in L1}
[e]
[w1w2] = L
So ind(R), the index of the equivalence relation, is 3, therefore finite. Hence, L is regular. Q.E.D.
To make it more clear, just have a look at the definition of the equivalence relation for languager, i.e. R_L.
Moreover, regular languages are closed under concatenation. De facto you just need to concatenate the two DFA/NFA's into one.

What are the parsing algorithms for programmed grammars?

I want to know what are the parsing algorithms used for parsing programmed grammars. Any Links , blogs or anything where i can read about programmed grammars and there parsing algorithms except IEEE research papers ?
I think it's explained well in The power of programmed grammars with graphs from various classes:
A context-free grammar is specified as a quadruple G = (N, T, S, P), where N
is a finite non-empty set called the nonterminal alphabet, T is a finite non-empty set called the terminal alphabet (N ∩ T = ∅), S ∈ N is the start symbol, and P
is a finite subset of N × (N ∪ T)∗ called the set of rules. Rules are also named
as productions.
A programmed grammar (without appearance checking) is a six-tuple G =
(N, T, S, Lab, P, PG) where N , T and S are specified as in a context-free grammar, Lab is an alphabet (of labels), P is a finite set of context-free rules called
the set core productions, and PG is a finite set of triples r = (q, p, σ), where
q ∈ Lab is the label of r, p ∈ P is a context-free production called the core
production of r, and σ is a subset of Lab and is termed the success field of r.
The elements of PG are called the rules of G.
The language L(G) generated by a programmed grammar G specified as above
is defined as the set of all words w ∈ T∗ such that there is a derivation
S = w0 =⇒r1 w1 =⇒r2 w2 =⇒r3 . . . =⇒rk wk = w,
where k ≥ 1 and, for 1 ≤ i ≤ k, wi−1 = wi−1 Ai wi−1 and wi = wi−1 vi wi−1
for some words wi−1 , wi−1 ∈ (N ∪ T)∗ , ri = (qi , Ai → vi , σi) and, for i < k,
qi+1 ∈ σi.
Excuse the lack of LaTeX.
In a similar way that Ogden's Lemma is stronger than the Pumping Lemma (because of markings), the concept of programmed grammar is stricter than context-free because of these labellings.

Resources