
HTML + CSS3 is Turing complete - bgruber
https://github.com/elitheeli/oddities/blob/master/rule110-grid.html
======
elitheeli
Way to steal my karma.... :)

As the original author of this, I was going to put it into a much more
presentable state before showing it off here.

For those confused, here's a proper explanation. No real-world thing can
actually be Turing complete (able to express basically any computation that we
might want to perform of any size). That's because there are finitely many
atoms in the universe, so we can only construct machines of finite size.

It's well known that Rule 110 (Google it) is Turing Compete.

What I've done is made an implementation of Rule 110 in HTML and CSS. Since
CSS can't actually really manipulate state, some user interaction is required
to "drive" it. In the one that bgruber linked to, it's clicking.

Here's a bigger version that doesn't require the user to know where to put his
mouse. The tab-space combo is just as legitimate as requiring that you plug a
computer into a wall to power it in order to run a Java program.
<http://elilies.com/rule110-full.html>

Also, I haven't tested it on anything besides the latest Chrome on Mac.

~~~
hasenj
> No real-world thing can actually be Turing complete

But when you say Turing-complete, I assume something along the lines of "a
programming language can be built on top of it and you can create interactive
applications using such a programming language instead of javascript".

It seems like that's not the case at all.

~~~
lukeschlather
Everyone's being a little cagey about what Turing Completeness really means,
in layman's terms, because I think the assumption is that if you're here, you
should already have a deep understanding of it.

So no, as others have said, you are completely off base as to what the
significance of being Turing complete is. What Turing complete means is that
given an infinite amount of memory and time, a language can simulate anything
that is computable. (I won't get into what computable means, for that you will
need to read and reread the relevant Wikipedia articles, along with a good
book on Theory of Computation and probably a good one on Abstract Algebra.)

But the real significance of this is that you cannot write a program that can
tell you meaningful facts about the behavior of an arbitrary Turing machine.
For any program you write to determine the behavior of HTML + CSS, I could
write a piece of HTML + CSS that your program will be unable to say anything
about.

However, this particular proof actually only shows HTML + CSS is equivalent to
a Linear Bounded Automaton, which unlike a Turing Machine can be predicted.
And strictly speaking, even if you have a Turing-machine-equivalent language
like C++, you can theoretically make some predictions about programs provided
you can bound its memory, i.e., on a machine with less than 4 GB of memory, it
is equivalent to a Linear Bounded Automaton. Now, of course actually writing a
second program to do this may be impossible to do before the heat death of the
universe, because Linear Bounded Automatons are still very powerful computing
objects.

~~~
shasta
"But the real significance of this is that you cannot write a program that can
tell you meaningful facts about the behavior of an arbitrary Turing machine.
For any program you write to determine the behavior of HTML + CSS, I can write
a piece of HTML + CSS that your program will be unable to say anything about."

Sorry, but this is false and for similar reasons is not reasonably considered
Turing complete. The encoding presented here produces, for any particular HTML
+ CSS, a finite number of cells of an automata (and not only that, the number
of cells is _linear_ in code size). That means that deciding any property
about a given piece of code amounts to search over a finite space.

This is very different from true Turing completeness where a small set of
rules might require unbounded space and computation to decide, and in general
will not even be decidable. Now, the author of this code says in a parent post
that we can't build a real Turing machine. That's true, but doesn't mean that
we can't specify a real Turing complete process; it just means that for some
executions we have to give up on running them.

In some cases, it makes sense to consider languages that are not actually
Turing complete as approximately Turing complete. For example, if you take the
C programming language, with a 64 bit memory space, then again there's
technically only a finite space of possible program states. But in that case,
you can have a 100 line C program that can generate 2^64 possible program
states. Turing completeness is a reasonable approximation. If you had to
allocate every bit of memory explicitly with a unique line of C code, it would
no longer be very reasonable to consider C approximately Turing complete.

~~~
lukeschlather
Yes, you're right, I've edited my post a bit to make it clearer that HTML+CSS
is not Turing complete.

------
CJefferson
I'd like a more complete description of this.

My first thought is "no it's not", because you are encoding a fixed-sized grid
in the HTML, which is then the total extent of the program. While no real
machine has an "infinite tape", I think requiring the tape be embedded in the
program itself is strengthing things a little far.

~~~
samdk
Why is it stretching things a little far? Non-infinite tape is, as you noted,
a limit on _everything_ we consider turing complete: this is just running at a
much higher level of abstraction than your computer. You could (if you were so
inclined) create a physical machine with a grid of memory that behaved
according to rules defined by CSS selectors. Just because this doesn't do
direct memory access and behave like the computer or a traditional TM doesn't
make it not a TM. (Or, at least, any less of a TM than the computer you're
using.)

~~~
kenjackson
The real question is if this can deal with arbitrary amounts of finite memory.
That is, could I express an instance of a program that requires a trillion
"units" of memory w/o constructing a new "machine" that explicitly laid it
out?

------
kcl
There are two competing definitions of Turing complete here.

1\. The mathematical definition of Turing completeness: models which can
simulate the computation of a hypothetical Turing machine. Idealized circuits
are an example of this. Turing machines are an example of this. Programs with
infinite memory are an example of this.

2\. The colloquial definition of Turing completeness: this is naturally ill-
defined, but it roughly means an automated, finite model that performs
arbitrary computation. I would say that a robotic Lego Turing machine is
Turing complete. C is certainly Turing complete in this sense. Basic HTML
isn't. The set of regexes (e.g, unix wildcards) isn't.

However, if I can choose a large enough regex, I can construct a decider for a
given finite language. How then are regexes less powerful than C? The answer
is they are just as powerful in the finite case, unless we set reasonable
limits on what we mean by 'finite' and 'automated.'

This HTML+CSS is not Turing complete. The idealized version of this HTML+CSS
is not Turing complete (unless you strangely accept the idealization of a
"hand pressing tab space"). This HTML+CSS is also not Turing complete in the
colloquial sense: it doesn't live up to the generally accepted notion of
automation. It isn't executed by the machine.

~~~
dmm
> However, if I can choose a large enough regex, I can construct a decider for
> a given finite language.

What do you mean by this? What is a "decider"? What do you mean by a finite
language?

~~~
anorwell
Language: <http://en.wikipedia.org/wiki/Formal_language>

Decision problem: <http://en.wikipedia.org/wiki/Decision_problem>

Decider: <http://en.wikipedia.org/wiki/Machine_that_always_halts>

These are fairly foundational concepts when talking about computational
complexity.

~~~
dmm
> However, if I can choose a large enough regex, I can construct a decider for
> a given finite language. How then are regexes less powerful than C?

Ok so upon reflection I think I see what you are getting at. Practical
computers are have limited memory and so are, in principle, equivalent to a
finite state machine.

So anything a practical computer can do a, perhaps ridiculously large, regular
expression can also do?

Is that close?

------
setnorth
As far as I remember is LaTeX (or TeX itself) touring complete, too. In the
end, if you can simulate a turing machine (or another "equivalent" calculating
"device") the language is itself turing complete. While not being a html/css
wizard, by the amount of complex examples i saw you could do with only
HTML/CSS3, I am not surprised that you can write a cellular automaton in it.

edit: typo (personal hangup with touring/turing)

~~~
elitheeli
TeX is very Turing complete. As is Java sans semicolons, C macros, and many
other things that probably shouldn't be. Right now, I'm trying to figure out
what the minimum number of characters you need in Ruby is to make it Turing
complete. I'm pretty sure that if you restrict yourself to under 12
characters, it's still possible.

~~~
Xk
C macros are not Turing complete, they're a pushdown automaton.

C++ templates are.

Check out this IOCCC entry which does simulate a Turing machine, but only by
having another script repeatedly run it.

Edit: Yes, I meant to copy the link, see mchouza's comment for the link.

~~~
mchouza
Link: <http://www.ioccc.org/2001/> (herrmann1 files)

------
hasenj
I don't understand .. explain?

EDIT: part of not understanding is I ran it in firefox 3.5 -- not good. works
better in chrome.

~~~
scotth
<http://en.wikipedia.org/wiki/Rule_110>

------
ssp
I'm probably tilting at windmills, but it's Turing _Equivalent_ , not Turing
_Complete_.

~~~
sid0
It'll be a really big deal the day we find a model of computation more general
than Turing machines. Till then, in most contexts they're interchangeable.

Also, if you really want to tilt at windmills, Turing complete is a weaker
statement than Turing equivalent, so he isn't _wrong_.

~~~
ssp
No, you are misunderstanding.

A language _L_ is _complete_ for a complexity class _C_ if it is _in_ _C_ and
all languages in _C_ can be reduced to _L_. "Turing" is not a complexity
class, so "Turing Complete" is nonsense. And if it _did_ mean something, it
would probably refer to a recursive language to which all other recursive
languages could be reduced.

"Turing Equivalent" is something a programming language can be and doesn't
have much to do with complexity theory.

~~~
sid0
_"Turing" is not a complexity class, so "Turing Complete" is nonsense._

Good thing that complexity theory isn't the only part of CS that uses the
notion of completeness. Turing (aka recursively enumerable functions) is a
_computability_ class, and it makes sense to talk about models of computation
complete for that class.

------
taylorbuley
<http://jsbin.com/owehi4/>

