Is it possible to determine the number of states in a minimal DFA without explicitly constructing it? - finite-automata

Is there any short answer or formula for determining the number of states in a DFA according to any language? more precisely is it possible to determine the number of states in a minimal DFA without explicitly constructing it?

Well I don't know about "short", but there is a heuristic that can be used. This is basically a restatement of the result of the Myhill-Nerode Theorem.
Given an alphabet and a language that is a subset of all strings over that alphabet, say that two strings x and y are equivalent if for any other string z the concatenations xz and yz are either both in the language or both not in the language. (note that z can be the empty string)
For example, if the alphabet is just 0 and 1, and the language is "all strings that end in 11", then the strings "0010" and "1110" are equivalent, because if z ends in 11 then both concatenations are in the language and if z does not end in 11, neither concatenation is in the language. Note that the string "0001" is not equivalent to those other two, because if z is "1", then the concatenation "0001" + "1" is in the language, but the concatenation "0010" + "1" is not in the language.
Then, the number of states in a minimal DFA for the language is the number of equivalence classes under this definition of "equivalent".
Following the example from before, the equivalence classes are "strings that do not end in a 1" (so, strings that end in 0 or the empty string), "strings that end in a 1 but do not end in 11", and "strings that end in 11". Therefore, the minimal DFA for this language consists of three states.
The only application I know of is the proof that the regular language for "numbers in some fixed base b that are divisible by n" requires at a minimum n states.

Related

Removing or adding the empty word from a DFA

The title is my interpretation of this question. Below is what I have attempted so far:
Case 1: Ɛ ∈ L(M)
L(M1) = L(M)
L(M2) = {Q2, Σ2, q20, F2, 𝛿2}
Q={q0, ... , qi}
Q2={q20, ... , q2i+1}
Σ2 = Σ
q2i+1 ∈ F2 iff qi ∈ F
𝛿2(q2i+1, a) = 𝛿(qi, a)
Case 2: Ɛ ∉ L(M)
L(M2) = L(M)
L(M1) = {Q1, Σ1, q10, F1, 𝛿1}
...
What you have so far looks good but incomplete. Here's a description of what's left; writing it out in symbols is left as an exercise.
In the first case, if the language already contains the empty string, we're done and can use the automaton for the language directly with no modification. If it does not contain the empty string already, we can add a new initial state and have it transition like the original initial state. If we leave all other transitions alone and make this new initial state accepting, we will accept the empty string as well as anything the original automaton accepted.
In the second case, if the language does not already contain the empty string, we're done and can use the automaton for the language directly with no modification. If it does contain the empty string already, we can add a new initial state and have it transition like the original initial state. If we leave all other transitions alone and don't make this new initial state accepting, we will not accept the empty string but will continue to accept everything else.
This is the best that can be done, in general. However, specific languages might have smaller automata than these constructed after adding or removing the empty string. For instance, the language consisting of only the empty string has a DFA with two states, but a minimal DFA for that language with the empty string removed has one state. Similarly, the language of all non-empty strings has a DFA with two states, but adding the empty string to that language means there's a one-state DFA for that language. So this construction does not always give the smallest DFA possible, but it is guaranteed to work for all cases, including those where there is no smaller DFA for the language (e.g., adding the empty string to the empty language forces the addition of a new state).

What does the operator := mean? [duplicate]

I've seen := used in several code samples, but never with an accompanying explanation. It's not exactly possible to google its use without knowing the proper name for it.
What does it do?
http://en.wikipedia.org/wiki/Equals_sign#In_computer_programming
In computer programming languages, the equals sign typically denotes either a boolean operator to test equality of values (e.g. as in Pascal or Eiffel), which is consistent with the symbol's usage in mathematics, or an assignment operator (e.g. as in C-like languages). Languages making the former choice often use a colon-equals (:=) or ≔ to denote their assignment operator. Languages making the latter choice often use a double equals sign (==) to denote their boolean equality operator.
Note: I found this by searching for colon equals operator
It's the assignment operator in Pascal and is often used in proofs and pseudo-code. It's the same thing as = in C-dialect languages.
Historically, computer science papers used = for equality comparisons and ← for assignments. Pascal used := to stand in for the hard-to-type left arrow. C went a different direction and instead decided on the = and == operators.
In the statically typed language Go := is initialization and assignment in one step. It is done to allow for interpreted-like creation of variables in a compiled language.
// Creates and assigns
answer := 42
// Creates and assigns
var answer = 42
Another interpretation from outside the world of programming languages comes from Wolfram Mathworld, et al:
If A and B are equal by definition (i.e., A is defined as B), then this is written symbolically as A=B, A:=B, or sometimes A≜B.
■ http://mathworld.wolfram.com/Defined.html
■ https://math.stackexchange.com/questions/182101/appropriate-notation-equiv-versus
Some language uses := to act as the assignment operator.
In a lot of CS books, it's used as the assignment operator, to differentiate from the equality operator =. In a lot of high level languages, though, assignment is = and equality is ==.
This is old (pascal) syntax for the assignment operator. It would be used like so:
a := 45;
It may be in other languages as well, probably in a similar use.
A number of programming languages, most notably Pascal and Ada, use a colon immediately followed by an equals sign (:=) as the assignment operator, to distinguish it from a single equals which is an equality test (C instead used a single equals as assignment, and a double equals as the equality test).
Reference: Colon (punctuation).
In Python:
Named Expressions (NAME := expr) was introduced in Python 3.8. It allows for the assignment of variables within an expression that is currently being evaluated. The colon equals operator := is sometimes called the walrus operator because, well, it looks like a walrus emoticon.
For example:
if any((comment := line).startswith('#') for line in lines):
print(f"First comment: {comment}")
else:
print("There are no comments")
This would be invalid if you swapped the := for =. Note the additional parentheses surrounding the named expression. Another example:
# Compute partial sums in a list comprehension
total = 0
values = [1, 2, 3, 4, 5]
partial_sums = [total := total + v for v in values]
# [1, 3, 6, 10, 15]
print(f"Total: {total}") # Total: 15
Note that the variable total is not local to the comprehension (so too is comment from the first example). The NAME in a named expression cannot be a local variable within an expression, so, for example, [i := 0 for i, j in stuff] would be invalid, because i is local to the list comprehension.
I've taken examples from the PEP 572 document - it's a good read! I for one am looking forward to using Named Expressions, once my company upgrades from Python 3.6. Hope this was helpful!
Sources: Towards Data Science Article and PEP 572.
It's like an arrow without using a less-than symbol <= so like everybody already said "assignment" operator. Bringing clarity to what is being set to where as opposed to the logical operator of equivalence.
In Mathematics it is like equals but A := B means A is defined as B, a triple bar equals can be used to say it's similar and equal by definition but not always the same thing.
Anyway I point to these other references that were probably in the minds of those that invented it, but it's really just that plane equals and less that equals were taken (or potentially easily confused with =<) and something new to define assignment was needed and that made the most sense.
Historical References: I first saw this in SmallTalk the original Object Language, of which SJ of Apple only copied the Windows part of and BG of Microsoft watered down from them further (single threaded). Eventually SJ in NeXT took the second more important lesson from Xerox PARC in, which became Objective C.
Well anyway they just took colon-equals assiment operator from ALGOL 1958 which was later popularized by Pascal
https://en.wikipedia.org/wiki/PARC_(company)
https://en.wikipedia.org/wiki/Assignment_(computer_science)
Assignments typically allow a variable to hold different values at
different times during its life-span and scope. However, some
languages (primarily strictly functional) do not allow that kind of
"destructive" reassignment, as it might imply changes of non-local
state.
The purpose is to enforce referential transparency, i.e. functions
that do not depend on the state of some variable(s), but produce the
same results for a given set of parametric inputs at any point in
time.
https://en.wikipedia.org/wiki/Referential_transparency
For VB.net,
a constructor (for this case, Me = this in Java):
Public ABC(int A, int B, int C){
Me.A = A;
Me.B = B;
Me.C = C;
}
when you create that object:
new ABC(C:=1, A:=2, B:=3)
Then, regardless of the order of the parameters, that ABC object has A=2, B=3, C=1
So, ya, very good practice for others to read your code effectively
Colon-equals was used in Algol and its descendants such as Pascal and Ada because it is as close as ASCII gets to a left-arrow symbol.
The strange convention of using equals for assignment and double-equals for comparison was started with the C language.
In Prolog, there is no distinction between assignment and the equality test.

Finite Automata Definition of language

Hi I am trying to define a language accepted by an FA in simple terms the FA is:
I think it is the language with strings
(not starting with ab and
not having substring bb and also ending with an a)
and also the NULL string
But I do not know if this is the shortest definition or correct at all?
All the even length strings which do not have 'b' at any of the even positions.
You are right. The FA defines a language containing all strings with a succession of aa and ba . The strings do not start with ab and never contain a bb. A more concise regex is (aa|ba)*
Any count of ("aa" or "ba") is possible (0 times too).
As regexp ([ab]a)*
In other words: Even count of characters, each odd position is a or b, and the rest only a.
Your definition is lacking the "even count" part, to start with.

How can I construct finite automata

I have to create a deterministic finite automata accepting the set of strings with an even number of 1 and ends with 0.Should I include 0 as a string from this set? and how can I do this?
Should I include 0 as a string from this set?
Yes
And how do I do this?
To construct a finite automaton, you need to identify the states and transitions. The Myhill-Nerode theorem allows you to find the necessary (and sufficient!) states of for a finite automaton if you are able to identify the equivalence classes of "indistinguishable" strings.
Two strings x and y are indistinguishable, in this sense, if for any other string z, either both xz and yz are in the language, or neither is.
In your case, let's try to identify equivalence classes. The empty string is in some equivalence class. The string 0 is in a different equivalent class, since you can add the empty string to 0 and get a string in the language (whereas you can't add the empty string to the empty string to get a string in the language). We have found two distinct equivalence classes so far - one for the empty string, one for 0. Both of these will need different states in our FA.
What about the string 1? It's distinguishable from both 0 and the empty string, since you can add 10 to 1 to get 110, a string in the language, but you can't add it to 0 or the empty string to get a string in the language. So we have yet another state.
What about the string 00? This string is not in the language, and no other string can be added to this string to get a string in the language. This is another equivalence class. It turns out that the next strings, 01 and 10, are also in this class.
The string 11 ends up being in the same class as the empty string: you can add any string in the language to 11 and get another string in the language. If you try all strings of length 3, you will find that all of those already fall into one of the above classes, and you can stop checking at that point.
So we have four states - let's call them [-], [0], [1], and [00]. Now we figure out transitions.
If you get a 0 in [-], you need to go to [0]... and if you get a 1, you need to go to [1]. For the rest, just figure out what string you'd get by adding to the canonical one, and which class the resulting string would be in... and go to that state.
Given Question is to construct a Finite Automata with even number of 1's and ends with 0.
So the alphabet of the language is {0,1}
These are the the strings that are accepted by the language.
The Language always consists of '0' before its final state as it is the end of the string and we reach the final state when we reach the last '0' in the string.
Here in the normal procedure of conversion of it into the finite automata we get NFA
Then we need to convert the NFA to DFA by combining 2 states into single and simplifying them.
New transition diagram
Here we had drawn the new transition diagram based on the states reached by a specific state at a given input. Then the new states formed by joining 2 states [ here {q0,q2} state is formed]
This new state {q0,q1} on 0 as input goes to itself (as q0 on 0 goes to q0 and q2 on 0 goes to q2).
So let us conside this new state {q0,q2} as a new state q2'
So by using the Transition state diagram we can easily make the required DFA
Deterministic Finite Automata
The above diagram is the constructed finite automata accepting the set of strings with an even number of 1's and ending with 0.
q0 - is the Initial state
q2'- is the Final state

Who "invented" i,j,k as integer counter variable names? [duplicate]

This question already exists:
Closed 13 years ago.
Possible Duplicate:
Why are we using i as a counter in loops
I've used these myself for more than 15 years but cannot really remember how/where I picked up that habit. As it is really widespread, I'm curious to know who originally suggested / recommended using these names for integer loop counters (was it the K&R book?).
i = integer
Comes from Fortran where integer variables had to start with the letters I through N and real variables started with the other letters. Thus I was the first and shortest integer variable name. Fortran was one of the earliest programming languages in widespread use and the habits developed by programmers using it carried over to other languages.
(From: Why are we using i as a counter in loops)
Obviously, j and k are just the next ones in your favorite alphabet.
The Mathematicians :)
It's common from school-level and college-level algebra exercises (although x and y had their part to play, there, too :-)
Also, if I remember correctly, the early programming languages (like early versions of FORTRAN) used variable naming in a way where initial letters were significant, and this may have had a part to play. For example, as this page says:
A FORTRAN variable is a way of
referring to a cell of the computer.
Names for variables must conform to
the following rules:
The name may be from one to six characters.
The first character must be a letter.
Characters other than the first may be letters or numeric digits.
If the first character is I, J, K, L, M or N, the variable is integer
(i.e. can hold a whole number value).
Otherwise, it is real (i.e. can hold a
value according to the floating point
convention).
FORTRAN. If the first character is I, J, K, L, M or N, the variable is integer (i.e. can hold a whole number value). Otherwise, it is real (i.e. can hold a value according to the floating point convention).
I always thought i stands for index as used eg in sum formulas in mathematics.
From the wikipedia for Loop Counter
A common identifier naming convention
is for the loop counter to use the
variable names i, j and k (and so on
if needed), where i would be the most
outer loop, j the next inner loop,
etc. The reverse order is also used by
some programmers. This style is
generally agreed to have originated
from the early programming of FORTRAN,
where these variable names beginning
with these letters were implicitly
declared as having an integer type,
and so were obvious choices for loop
counters that were only temporarily
required. The practice also dates back
further to mathematical notation where
indices for sums and multiplications
are often i, j, etc.