Set of conditions for Finite Automata transitions - automata

What kind of Finite Automata supports set of conditions for transaction from state A to state B? For example, if (a && b && c) then A -> B.
To make it even harder, let's say that we receive one condition at a time.
of course it could be done with DFA, but that will lead to state explosion

It doesn't matter whether you use NFA or DFA as you can subsequently apply the so-called powerset construction in order to minimize it. This yields the smallest possible automaton for your defined language.

Related

Theory: LL(k) parser vs parser for LL(k) grammars

I'm concerned about the very important difference between the therms: "LL(k) parser" and "parser for LL(k) grammars". When a LL(1) backtracking parser is in question, it IS a parser for LL(k) grammars, because it can parse them, but its NOT LL(k) parser, because it does not use k tokens to look ahead from a single position in the grammar, but its exploring with backtracking the possible cases, regardless that it still uses k tokens to explore.
Am I right?
The question may break down to the way the look-ahead is performed. If the look-ahead is actually still processing the grammar with backtracking, that does not make it LL(k) parser. To be LL(k) parser the parser must not use the grammar with backtracking mechanism, because then it would be "LL(1) parser with backtracking that can parser LL(k) grammars".
Am I right again?
I think the difference is related to the expectation that LL(1) parser is using a constant time per token, and LL(k) parser is using at most k * constant (linear to the look-ahead) time per token, not an exponential time as it would be in the case of a backtracking parser.
Update 1: to simplify - per token, is the parsing LL(k) expected to run exponentially in respect to k or in a linear time in respect to k?
Update 2: I have changed it to LL(k) because the question is irrelevant to the range of which k is (integer or infinity).
An LL(k) parser needs to do the following at each point in the inner loop:
Collect the next k input symbols. Since this is done at each point in the input, this can be done in constant time by keeping the lookahead vector in a circular buffer.
If the top of the prediction stack is a terminal, then it is compared with the next input symbol; either both are discarded or an error is signalled. This is clearly constant time.
If the top of the prediction stack is a non-terminal, the action table is consulted, using the non-terminal, the current state and the current lookahead vector as keys. (Not all LL(k) parsers need to maintain a state; this is the most general formulation. But it doesn't make a difference to complexity.) This lookup can also be done in constant time, again by taking advantage of the incremental nature of the lookahead vector.
The prediction action is normally done by pushing the right-hand side of the selected production onto the stack. A naive implementation would take time proportional to the length of the right-hand side, which is not correlated with either the lookahead k nor the length of the input N, but rather is related to the size of the grammar itself. It's possible to avoid the variability of this work by simply pushing a reference to the right-hand side, which can be used as though it were the list of symbols (since the list can't change during the parse).
However, that's not the full story. Executing a prediction action does not consume an input, and it's possible -- even likely -- that multiple predictions will be made for a single input symbol. Again, the maximum number of predictions is only related to the grammar itself, not to k nor to N.
More specifically, since the same non-terminal cannot be predicted twice in the same place without violating the LL property, the total number of predictions cannot exceed the number of non-terminals in the grammar. Therefore, even if you do push the entire right-hand side onto the stack, the total number of symbols pushed between consecutive shift actions cannot exceed the size of the grammar. (Each right-hand side can be pushed at most once. In fact, only one right-hand side for a given non-terminal can be pushed, but it's possible that almost every non-terminal has only one right-hand side, so that doesn't reduce the asymptote.) If instead only a reference is pushed onto the stack, the number of objects pushed between consecutive shift actions -- that is, the number of predict actions between two consecutive shift actions -- cannot exceed the size of the non-terminal alphabet. (But, again, it's possible that |V| is O(|G|).
The linearity of LL(k) parsing was established, I believe, in Lewis and Stearns (1968), but I don't have that paper at hand right now so I'll refer you to the proof in Sippu & Soisalon-Soininen's Parsing Theory (1988), where it is proved in Chapter 5 for Strong LL(K) (as defined by Rosenkrantz & Stearns 1970), and in Chapter 8 for Canonical LL(K).
In short, the time the LL(k) algorithm spends between shifting two successive input symbols is expected to be O(|G|), which is independent of both k and N (and, of course, constant for a given grammar).
This does not really have any relation to LL(*) parsers, since an LL(*) parser does not just try successive LL(k) parses (which would not be possible, anyway). For the LL(*) algorithm presented by Terence Parr (which is the only reference I know of which defines what LL(*) means), there is no bound to the amount of time which could be taken between successive shift actions. The parser might expand the lookahead to the entire remaining input (which would, therefore, make the time complexity dependent on the total size of the input), or it might fail over to a backtracking algorithm, in which case it is more complicated to define what is meant by "processing an input symbol".
I suggest you to read the chapter 5.1 of Aho Ullman Volume 1.
https://dl.acm.org/doi/book/10.5555/578789
A LL(k) parser is a k-predictive algorithm (k is the lookahead integer >= 1).
A LL(k) parser can parse any LL(k) grammar. (chapter 5.1.2)
for all a, b you have a < b => LL(b) grammar is also a LL(a) grammar. But the reverse is not true.
A LL(k) parser is PREDICTIVE. So there is NO backtracking.
All LL(k) parsers are O(n) n is the length of the parsed sentence.
It is important to understand that a LL(3) parser do not parse faster than a LL(1). But the LL(3) parser can parse MORE grammars than the LL(1). (see the point #2 and #3)

Deterministic Pushdown automa vs Non-deterministic pushdown Automata

how can you show a) Deterministic pushdown automata (DPDA) are more powerful than finite automata and less powerful than a non-determinstic pushdown automata?
(1) First, show that any language that can be accepted by a finite automaton can also be accepted by a deterministic pushdown automaton. Recall that any language accepted by a finite automaton is accepted by a deterministic finite automaton, and a deterministic pushdown automaton can simulate a deterministic finite automaton simply by doing nothing interesting with its stack. Next, show there is a non-regular language accepted by a DPDA. 0^n 1^n is a good candidate. Prove this language is non-regular using the pumping lemma or Myhill-Nerode theorem, thenshow the DPDA that pushes on 0s and then switches to popping on 1s works.
(2) First, note that NPDAs can accept any language accepted by DPDAs since all DPDAs are also NPDAs that happen not to make use of nondeterminism. Next, find a language that has an NPDA but no DPDA. Even-length palindromes over the alphabet {0, 1} might work. There is a simple NPDA for this that nondeterministically guesses when the first half of the input has been read and switches from pushing to popping. To show there is no DPDA is more challenging. Perhaps you could argue as follows: suppose there were a DPDA. Then, in any configuration of the DPDA, only one transition would be possible. If string w leads to an accepting state in the DPDA and empties the stack, x00 may lead either to an accepting or non-accepting state (since x00 either may or may not be an even-length palindrome). This is a contradiction, though, so our DPDA does not exist. The same argument fails for NPDAs, by the way, because there can be multiple paths through, so one failed choice means nothing.
NDPA is more powerful than DPDA because we can add more transitions to it. It is possible for every language to add a transition. For some languages, we can construct DPDA there exist an NPDA but there are some languages that are accepted by NPDA but are not by DPDA. This is said to be powerful when it accepts more sets of languages than other automata.
In fact, it is more powerful than DFA(Deterministic finite automata) and NFA(Non-deterministic finite automata) also because, In the case of DFA and NFA, they are equivalent in power. So for every language accepted by DFA there exist an NFA and Vice-Versa. There is not any language for which we construct NFA but not DFA. Hence, we can’t convert NPDA to DPDA always and we can convert NFA to equivalent dfa.

Why is figuring out if the cardinality of a language is not finite a "decidable" problem?

Given two finite-state languages L1 and L2, then determining their intersection is not finite is a decidable problem.
How can this be? Thanks.
Let M1 and M2 be minimal deterministic finite automata whose accepted languages are L1 and L2, respectively.
First, construct a deterministic finite automaton M3 whose accepted language is the intersection of L1 and L2 by using the Cartesian Product Machine construction - an algorithm which produces the desired machine.
Next, construct a deterministic finite automaton M4 which accepts the same language as M3, but which is minimal; that is, minimize M3 and call the result M4. There is an algorithm which produces this result.
Next, construct a deterministic finite automaton M5 which accepts only words of length strictly greater than k, where k is the number of states in M4. There is such a machine with k+1 states for any alphabet; its construction is not complicated.
Next, construct a deterministic finite automaton M6 whose accepted language is the intersection of the languages accepted by M4 and M5. Use the Cartesian Product Machine construction again here.
Next, construct a deterministic finite automaton M7 by minimizing M6.
At this point, either M6 is a deterministic finite automaton with one state which accepts no strings at all, or not. In the former case, the intersection of L1 and L2 is finite; in the latter case, that intersection is infinite. Why?
M1 accepts L1
M2 accepts L2
M3 accepts L1 intersect L2
M4 is a DFA accepts L1 intersect L2 and has as few states as possible
M5 accepts only words which would cause M4 to enter one of its states twice
M6 accepts only words in L1 intersect L2 that also cause M4 to enter one of its states twice. Note that if M6 accepts anything, that means there are words in L1 intersect L2 which a minimal DFA for that language must loop to accept; because such a loop could be followed any number of times, this implies there must be infinitely many words in L1 intersect L2. This is closely related to the pumping lemma for regular languages.
M7 accepts what M6 does, but is minimal. Note that minimization is not necessary but it makes it trivial to check whether M6 accepts anything or not. The minimal DFA which accepts no string has one dead state. This is easy to check, and there are standard algorithms for minimization.
Another similar way of showing the same thing would be to say you can construct the DFA for the intersection and then check all strings of length from |Q| to |2Q|. No finite language will have any strings of these lengths accepted by a DFA for that language, but every infinite language will have at least one such string. This is because any DFA accepting an infinite language must loop, and the length of that loop must be no greater than the number of states.

Can a finite automata have more than one input states?

I was knowing that Finite Automata can have only one input states but several output states. Recently, I've come across an example of removing ^-moves that has many input states.
Please help!
Deterministic finite automata are equivalent to nondeterministic finite automata with epsilon/lambda transitions. Having multiple input/start/initial states is equivalent to having a single input/start/initial state with epsilon/lambda transitions to the desired input/start/initial states. It may not be "standard" or "usual" to speak of finite automata with multiple input/start/initial states but it adds no expressive or computational power.

Deterministic Finite Automata minimization

If we have a finite automaton with no final/accepting states. So that F is empty. How do you minimize it?
I got this to a test in which I was asked to minimize an automaton but it had empty F and I didn't know how to approach the problem because the automaton had no accepting states. Is a single initial state with all the transitions into itself the correctly minimized automaton?
I thought that if two automatons A and B for any possible input, A returns the exactly same output as B, they must be equivalent. Thus if an automaton has no final state, then it accepts no input or no input is valid, so it must be equivalent with any other automaton that behaves this way.
If the definition of Finite Automata enforces non empty state set, a single initial state without any transition will do.
Minimization of a finite automata helps in reducing the compile time, as it removes identical operations.
When we minimize an expression,we tend to remove the unused states or we merge two or more states into a single equivalent state which are likely to produce same output. Merging states like this should produce a smaller automaton that accomplishes exactly the same task as our original one. (Here the unreachable states are removed and the states are checked whether they are distinguishable or not. If undistinguishable the states are merged else the states are uniquely represented).
As it reduces the compilation time,results in increasing the processing speed of the program. Running a program which can run a second or two faster than other programs, can vastly increase the scope of the program.

Resources