
CSS3 proven to be Turing complete? - mmastrac
http://my-codeworks.com/blog/2015/css3-proven-to-be-turing-complete
======
Dylan16807
1\. Feeding infinite HTML is not the same as feeding tape. A million tape
cells can keep a typical Turing machine running indefinitely. A million rows
only keep this running for a million execution steps, which is what, a tenth
of a second if optimized?

2\. The 'crank' here is not part of CSS. Computer languages that are declared
'Turing complete' need to be able to crank themselves. You need to be able to
tell them to go, and wait. I accept that magic the gathering Turing machine,
(at least as long as you remove the word 'may'), because it's _part of the MtG
rule set_ that you continue performing all the state transitions until you
reach a halt.

3\. Allowing this completely external pump means that anything that can add
and multiply three numbers and then exit would be counted as Turing complete,
because you can then instantiate an infinite number of these and pump data
through. The Turing complete nature of that construction lies mostly in that
pump. It is not at all just a crank that say 'go'.

And 3 is really the important part here. None of the scary implications of
'Turing complete' come into play, because you can't take the result of one
arithmetic statement and feed it into more. All of that playing around is
roughly O(n) in terms of page size. Not O(unlimited) as 'Turing complete'
might imply.

~~~
d-Pixie
1\. Sure, but just since finite input can be handled quickly doesn't mean it's
not turing complete. A million cell tape for the Rule 110 automaton in any
language will probably execute in milliseconds, if at all optimised... There
might be other turing complete problems that can reuse tape the way you
suggest, but Rule 110 isn't one of them.

2\. In Turings own paper he envisions the "crank" to be a human. I think we
can all agree that a human is more than turing complete. The process of
feeding the next cell etc isn't part of what makes something Turing complete.
There is no requirement that it be self-cranking in Turings papers, nor the
current formal definitions I have read. Could you supply an example of where
this is brought up as a formal requirement?

3\. Well, yes. The point here lies in the _rules_. The method of executing the
rules doesn't really matter, as discussed in 2. Humans are > Turing complete
...

~~~
vectorjohn
About 2, sure. But when people say "X shown Turing complete", that doesn't
have much meaning unless the X is somehow doing it without external input.
Why? Because otherwise everything is Turing complete. Literally, "series of
bits proven Turing complete!", "line of rocks on a sidewalk Turing complete!"

Because, the fact that computers exist is not a surprise. I mean, the original
concept of a Turing machine is literally a tape and a read head.

~~~
smitherfield
I'm sorry if I totally butcher the fundamental concepts of Turing completeness
here; I was neither a CS nor a math major.

But as I understand it a Turing machine is a physical impossibility because it
is defined as having an infinite stream of data being inputted. And the
physical presence of an infinity of information is a physical impossibility (I
also wasn't a physics major, so I'm not sure if this violates physical laws or
is just a practical impossibility, but either way it's obviously impossible).

So instead of an infinite stream of input, we usually define something as
"Turing complete" if it's possible for it perform arbitrary computations on
arbitrary input supplied in real time. CSS3 cannot do this; programming
languages with real-time I/O can do this.

So CSS3 is "weakly" Turing-complete because it can perform arbitrary
computations on arbitrary data input supplied ahead of time. With an infinite
amount of random HTML-formatted data input ahead of time (same as a Turing
machine), it can be equivalent to a Turing machine. C or Javascript are
"strongly" Turing-complete because they can perform arbitrary computations on
arbitrary, properly-formatted data input supplied ahead-of-time _or_ in real
time.

------
murbard2
Two comments:

1) it's not surprising: a lot of very simple systems can compute. It seems to
naturally happen as you add flexibility to your rules. See for instance Wang
Tiles or some cellular automata.

2) it's not a good thing: it means that the behavior of CSS3 is undecidable in
general, which makes it much harder to build tools that can meaningfully
analyze it.

~~~
d-Pixie
I completely agree that it's not a good thing. I know that the browser
maintainers also see the increasing complexity of CSS as a bad thing. That's
why I was so sceptical to it from the start ...

~~~
api
GUIs tend to do this. I think the reason is that programmers fundamentally
underestimate the problem of building a good graphical user interface, and
therefore systematically design solutions that are inadequate. These
inadequate frameworks then accumulate ugly nasty cruft because their
underlying structure is not adequate to elegantly address the problem domain.

GUI toolkit and renderer development should begin with the humble admission
that building a good GUI system is _incredibly hard_ , on par with massive
distributed systems and AI, and that the problem should be tackled with that
level of difficulty as an expectation. A good analogy would be between a GUI
toolkit and a mature 3d virtual world game engine. Those are probably roughly
equivalent problem domains.

~~~
andrewflnr
AI=~=GUIs=~=3D game engine? One of these is not like the others, and I'm not
talking about the number of letters in the name. I take your point in general,
but I don't buy the idea that designing a good GUI system is as hard as AI or
distributed systems.

~~~
api
I dunno. Can you deal with right-to-left, left-to-right, and vertical
languages with different glyph forms on the same screen while also coping with
multiple accessibility settings, sub-pixel anti-aliasing, embeddable GL
components, component reusability, efficient updates on state changes without
a full re-render, and platform support for over 200 different graphics
chipsets?

I'm just saying it's a problem domain that is consistently underestimated.

~~~
murbard2
It's not the same type of difficult; it's extremely painstaking and it's by no
mean an easy task, but it's much less conceptually hard than a 3D engine, let
alone an AI.

------
vectorjohn
I'm skeptical a little, in that the article starts off by saying it is "more"
Turing complete than C. Something either is or is not Turing complete. The
nitpick that a C implementation has a pointer size which limits the memory to
!infinite is an unimportant implementation detail. If that's your argument,
nothing is Turing complete because the universe is made out of a finite amount
of matter and energy.

Also, as others have pointed out, it doesn't "run" unless an external thing is
pressing buttons. If you allow what are essentially external programs to run,
you might as well have Javascript doing the job, and then the headline becomes
a lot less interesting.

------
haberman
So CSS3 is both Turing complete _and_ so low-level that most projects of
significant size use a preprocessor like LESS, SASS, etc to write their CSS3
for them.

~~~
Spivak
What's your point? The same is true for x86 and you don't see many people
writing that by hand.

~~~
TeMPOraL
It means that JS-as-web-Assembler just got itself a competitor.

~~~
astazangasta
Boo! Boo to this comment and the horrors it may unleash.

------
forrestthewoods
That's horrifying. And I'd argue a damning indicator that CSS3 is wildly
overcomplicated. It really _shouldn 't_ be Turing complete.

~~~
akerro
Can you center images yet? :>

~~~
talmand
Such knowledge exists, but it requires a long and dangerous journey filled
with adventure, thrills, and excitement too bold for most to endure. Many have
traveled down that path, but few have returned to tell the tale.

I am one of those few.

I could easily share that knowledge, but for one to fully understand, one must
walk such a path thyself guided by the voices from the source that flows over
the stacks of such knowledge.

~~~
gotchange
As I walk through the valley of shadow of vertical-align, I took a look at my
codebase and I realize there isn't much left ...

------
fixermark
I think there's a flaw in the model.

"Assume that the amount of HTML currently loaded is finite but sufficient for
all of the state to be properly rendered."

So consider <html> <div class="myContainer"> <div>1</div> <div>2</div>
<div>3</div> . . .

I've never met an HTML streaming solution that won't just stream this
sequentially, which means no </div> for myContainer will ever be emitted (and
therefore the HTML will never be well-formed, and the CSS will never have
sufficient information to lay out).

If the HTML were streamed such that <html><div
class="myContainer"></div></html> were received, and then the interior of
myContainer were streamed, that'd be a different story, but that doesn't
exist. So I don't think this blog post's argument that CSS3 is Turing complete
works for any real implementation.

~~~
d-Pixie
What relevant CSS rule can't be applied to this? We know our previous context
and everything before which is what CSS acts on anyway, no lookahead rules in
CSS :)

And yes, there could come an yet as to unknown element later that changes the
display, displays on top of using position:absolute; for example, of current
content. But not that changes how current content itself is displayed.

------
dheera
Great, so now I can write an x86 emulator and run Windows 95 in CSS, but I
still can't figure out how to reliably vertically-center an element.

~~~
gotchange
There are two widely known techniques for vertically centering an element in
CSS that are virtually supported across the board:

    
    
        display: table-cell; vertical-align: middle;
    

or

    
    
        position: absolute; top: 50%; transform: translateY(-50%)
    

You can't really complain about that point anymore.

~~~
anonbanker
so hack it into a table cell, and valign like it's html 4.01 all over again,
or render the full page, then reposition content based on that size? am I
understanding these techniques correctly?

~~~
daxelrod
There's an important difference between creating a table in your HTML for
layout, and using CSS to tell the browser to use its table layout algorithm on
a particular element to center it.

Yes, it's still inelegant and nonobvious, but it's also better than throwing
document semantics out the window.

------
neocraftster
Does this mean that in addition to a javascript blocker i need a CSS blocker
to stop malicious code from being run in my browser?

~~~
d-Pixie
Not yet :)

