r/AskComputerScience • • Mar 20 '21

Why is theory of computation concerned with recognizing languages?

Michael Sipsers's book Introduction to the Theory of Computation introduces automata theory and theory of computation as fields of research trying to answer to questions of format is there an automaton that recognizes the language defined by grammar x. As a programmer, this seems weird. Why talk about recognizing languages rather than approaching the automaton as a computer program or a function, i.e. a series of instructions (or state transitions) mapping input to output? Intuitively, it seems like languages and grammars would only be iteresting to a computer scientist who is designing a programming language or writing a parser.

38 Upvotes

19 comments sorted by

23

u/beeskness420 Mar 20 '21

Because everything we do as computer scientists revolves around formal languages.

4

u/[deleted] Mar 20 '21

Why is this the case? What makes study of formal languages useful (except obviously topics related to programming language design & parsing)?

7

u/beeskness420 Mar 20 '21 edited Mar 20 '21

I dunno people seem to think math, computer science, and linguistics are pretty useful.

If we took the word game a step further and called programs “essays” would that be satisfactory?

6

u/[deleted] Mar 20 '21

I think I worded my comment poorly - I'm not suggesting it's not useful.

I guess my confusion stems from the fact that theory of computability is supposed to find which computational problems can and which can't be solved. Why is study of formal languages the best way to approach this problem? How does it even help us answer questions such as Is there a program that detects all bugs from another program.

13

u/redblack-trees Mar 20 '21

Why is study of formal languages the best way to approach this problem? How does it even help us answer questions such as

Is there a program that detects all bugs from another program.

This is a great question! The upshot is that we can only know something for sure if we formalize our propositions and write up a proof of what we're trying to show. Once you're able to transform a computer programming problem into a math problem, you open an enormous store of incredibly powerful tools that mathematicians have spent the last half-dozen millennia toiling over. Here's a link that I think shows a great example of that principle at work!

With regard to your question at the end, 'Is there a program that detects all bugs from another program.' – correct me if I'm wrong, but it sounds like you understand that the halting problem plays a role here, but you're not totally sure what form that takes. Let's try reducing your question to a simpler one, and say that we "only" want a program that detects all bugs that lead to infinite loops in another program. Here's where we would invoke the undecidability of the halting problem to say that this is an impossible task – if we didn't have a theory of formal languages, then we wouldn't even be able to ask our question in a precise way, let alone get such a clean answer! I'm sorry if I made anything less clear – please let me know whether this makes sense!

1

u/[deleted] Mar 20 '21

Yeah, I guess that makes sense. It's not like I have a better way in my mind to formalize the problems. Like I responded to your other comment, this approach seems weird from my perspective as a programmer but maybe it's not so weird from the perspective of a mathematician.

-4

u/beeskness420 Mar 20 '21

Because programs are formal systems, I’m not sure what else you would study other than formal languages.

What does your last question even mean? For it to have a real answer you need to formalize it.

1

u/[deleted] Mar 20 '21

Are all formal systems considered languages here? Obviously you need to formalize the problem but I'm not sure how that relates to the study of grammars, etc.

As to the example I gave, I'm not sure how I would formulate that problem in a format Is there an automaton that recognizes grammar x such that answer to that question would also give an answer to the original question. Or are we trying to create an automaton that takes a string as an input and tells us whether that string is a serialized version of a program that doesn't have bugs?

2

u/beeskness420 Mar 20 '21

Well you gotta decide on a model of computation. If your model is finite state automata then that question is exactly “is the language regular”.

You gotta formalize what a “bug” and a “program” are, but turns out a decent choice is to use Turing Machines as our model and call a program a TM. We’ll say our “program” has a “bug” if it doesn’t output a proper value or an error, so that would be if it doesn’t halt.

Then our language is the set of TM’s and inputs x, such that TM(x) halts. Is this language decidable, is it computable? If it’s not computable then we need a stronger model of computation to compute it. TM’s are the strongest model we expect to exist in the real world (outside of quantum or probabilistic) models.

So this means that any formal system with less or equal power to a TM cannot solve the halting problem. We haven’t made a reference to any real world system so it applies to all of them.

3

u/Poddster Mar 20 '21

Why is this the case?

I assume you've come across the concept of a programming language and a compiler? A compiler is an automaton that recognises the language defined by language X.

2

u/darthandroid Mar 20 '21

It's useful because a computer, at its heart, is fundamentally a programmable state machine. A program is the set of rules that define how the state machine transitions between states to accept input, in the form of a string of events (clicks, keypresses, network payloads, clock interrupts, etc).

To build any sort of proof that a program does what it needs to do (and doesn't do what it shouldn't do), we need a way to reason about how it behaves when presented with a set of inputs. Whether we're talking about variables and keypresses, or states and strings, at a mathematical level they are equivalent-- and states and strings provides a more universal way to reason across the entire discipline, and talk about design. For example:

Is there an automaton that recognizes the grammar of logging into a website?

Before you can begin translating that to an implementation in python or java or C# or any other programming language, you first have to understand the characters that make up the grammar:

{user enters correct username+password, user enters incorrect username+password, user requests a password reset, user completes a password reset, user enters 2FA code, user calls support to unlock their account, user logs out}

and the language itself; [user logs out, user logs out] is probably not valid, for example, anywhere in the language. [user enters correct username+password, user enters 2FA code] should probably be the only input that gets the user to the "logged in" state.

You can reason about this sort of thing a little bit in your head for very, very small languages without formalizing it or without realizing that you're formalizing it-- but if you want to share it with colleagues, verify that the design will behave as expected, make sure all the cases are being tested, etc. you will have to formalize it in some way. Does it need to be formalized to the same level as the mathematical proofs in research? Probably not. But the ideas and concepts are the same. The actual use of literal strings to drive an automata is an abstraction used in absence of a concrete problem and specific implementing language, while still allowing us to reason about about the system.

2

u/UncleMeat11 Mar 20 '21

"Language" does not mean what you think it means here. It is much broader than that. Instead it means "distinguishing between inputs of one kind and another kind". This, it turns out, is basically all there is to computation. It isn't that the theory is ignoring other stuff. There isn't other stuff when it comes to basic nature of what computers can and can't do.

4

u/redblack-trees Mar 20 '21

Complexity theorists are interested in automata theory because, according to all evidence we've seen thus far, there exists no realistic model of computation that surpasses the computational capacity of a Turing Machine. The same thesis (called the Church-Turing Thesis – iirc Sipser introduces this concept fairly early on) holds for Lambda calculus, which seems to be more like the model of computation that you're imagining. For what it's worth, linguists will always use Lambda calculus over TMs – maybe computer scientists just stick with TMs because we think TMs seem more like circuits? No idea.

I hope that answers your question, though. Sipser also lays it on a bit heavy for non-theory folks. If you're not going into theory, you likely won't ever use the complexity-theoretic proofs that appear in Part III. As fun as automata are, you'll likely only ever rely on results from computability theory and fine-grained complexity theory, both of which don't receive much attention from theoreticians nowadays.

3

u/[deleted] Mar 20 '21

True, I guess lamba calculus is kinda like that. When learning to program, we're taught to think of computer programs as functions that map input to output. With that background it just feels weird to think of them as automatons that recognize whether an input string is a member of a formal language. Maybe that approach made more sense when programming languages didn't even exist.

12

u/claytonkb Mar 20 '21

There are a couple solid replies but I'll chip in for what it's worth.

If you go back to Turing's 1936 paper, he was primarily interested in tackling the Entscheidungsproblem or "decision problem". From Wiki, "[The Entscheidungsproblem] is a challenge posed by David Hilbert and Wilhelm Ackermann in 1928. The problem asks for an algorithm that considers, as input, a statement and answers 'Yes' or 'No' according to whether the statement is universally valid, i.e., valid in every structure satisfying the axioms."

We could get into a lot of the back-history in formal logic that predates the era of computer science. But CS obsoletes many aspects of formal logic -- as an example, we now know that the Turing machine can decide any decidable problem and this means that there is no abstraction that is "more powerful" than a Turing machine, at least, not in the specific sense of deciding sentences constructed within a formal system. So, while the history of pre-CS formal logic is a fascinating topic of history, many of the questions that preoccupied formal logic in that era are no longer interesting to us. Remember, it was not obvious in that era that it was possible to build a machine which could be programmed to calculate just any mathematical function. Perhaps there was some faculty in the human mind that permits us to "directly perceive" solutions in non-mechanical ways. No one knew for sure that this wasn't the case. But today, we know that it is not the case (at least, if you believe the Church-Turing thesis, which can hardly be called controversial.)

For finite functions (functions that have finite domain and range), there is no obstacle to using the approach you suggest, just talking about logic circuits, automatons, and the like. But when you want to make claims about "all" this, "for none" that, or "for each" of the other, you want to be able to handle infinite sets. How many strings are there in the Kleene-star over B={0,1}, that is, B*? Why, there are infinitely many.

Suppose you want to say "there is no string s such that property P(s) holds." You need some abstraction that allows you to handle each and every string. You might prove this claim by positing the existence of a machine M that would recognize s if that is possible, and then proving that there is no machine M (perhaps proof by contradiction, or whatever). In this way, you have proven that the property P() does not hold for infinitely many strings. That's how you use a finite proof to do an infinite amount of work!

Another redditor mentioned the logical equivalence between recognizing a language versus generating the language. This equivalence is very powerful because, once again, it allows us to skip the hard work of trying to enumerate every possible example of strings with property P and, instead, just operate on a machine that would recognize such strings. Then we can just prove things about this machine (which is a finite object and so the proof is manageable.)

5

u/not-just-yeti Mar 20 '21 edited Mar 20 '21

Here's a partial answer, in two parts (a) and (b):

(a) Because they are equivalent:

  • "compute the square of a number" can be re-formulated as "the set of all strings of the form x#y, where stringToInt(y)=stringToInt(x)2 ".

In this case we're transformed the problem from computing-a-function to a 'verifier' version [which affects run-time], but you can also transform it into an optimization version ("is y within 10% of x2 ?"), or maybe something like "is y the checksum of x2 ?".

(b) the language-formulation seems to work better with regular languages and context-free languages, which don't have the same "computing" feel that TMs can have.

Note that when hitting TMs, texts do start to talk about "TMs that accept/reject/loop-on an input" vs "TMs that compute a function", and they tweak the accept/reject state criteria a bit, to capture the 2nd view.

BUT to get to the real nub of your question: I do not know whether a re-formulation of the all the results into a 'compute-function' approach would make standard results easier, harder, or [most likely:] just different. (You'd want to include both classic results through 1980s, plus the interactive-prover results from the 90s onwards.)

It could easily be, as you suggest, that the classical theory was worked out at the same time many other CS people were concerned about implementing parsers, and that the bias of the Zeitgeist set down the initial formalism as determining set-membership rather than compute-function. And since they're usually easy to convert between, it's not worth trying to change everybody's phrasing of the topic?

2

u/chien-royal Mar 21 '21

Theory of computation can be presented primarily using functions rather than languages. This is done, for example, in the book "Theory of Recursive Functions and Effective Computability" by Hartley Rogers. For another example, Rice's theorem in Wikipedia is stated in terms of functions, so this creates an inconvenience for me whenever I want to provide a link to some discussion about undecidable languages. Finite automata also don't have to only recognize languages: there are finite-state transducers, in particular Mealy and Moore machines.

In fact, in Russia it is more customary to teach theory of computation using functions than languages. There is basically only one good language-based textbook, which is a translation of "Introduction to Automata Theory, Languages, and Computations" by Hopcroft, Motwani and Ullman.

2

u/l_lecrup Mar 21 '21

All the top answers were incomplete or a bit unclear. It's actually very simple:

Decision problems and formal languages are equivalent.

In fact, if you try to define decision problems in a nice way computationally you are almost guaranteed to rediscover formal languages. You encode inputs as strings, the yes-inputs form a language, and you have reduced decision problems to deciding formal languages.

In the real world of course we want to know about more general problems than decision problems, but for all function problems a decision problem that is "easier" exists, and we don't fully understand decision problems (P vs NP is about decision problems, or equivalently about formal languages), so from a theoretical point of view it makes sense to focus on those. Recognition just means one-sided decision, i.e. you claim success if your computer can recognise yes-instances/members of the language and it's allowed to run for ever otherwise. That's a way of giving more power to computers, not unlike giving them non-determinism or a coin flip.

1

u/javaHoosier Mar 20 '21

It sounds like you haven’t made it to complexity theory yet.

A formal language is actually quite simple. It’s just a set. How else would you describe what you want all acceptable input to be?

Then down the road you categorize these languages based on what model of computational can recognize them and beyond.

You can pose a problem and hopefully reduce to another problem and understand the complexity class. There are tons of problems out there that could change the world if a more optimized algorithms are discovered. Or we can attempt to prove that their isn’t.