Hacker News new | ask | show | jobs
by SamReidHughes 2495 days ago
Without conditionals, every program either terminates after a pre-specified amount of computation or never terminates. That leaves you extremely limited in what you can accomplish (less powerful than a DFA).

A DFA or maybe a 2DFA (which are equally powerful) is basically what you get when all you have is conditionals.

Without that, what you have is a box that can read finite input and compute a value. Equivalent to a finite lookup table.

1 comments

It's not as much of a limitation as people think. One pattern is for the program to update a state every (fixed-length) iteration. You can build any arbitrary computation on top of that.
Can you provide an example? I have a hard time believing any arbitrary computation can be build without conditionals.
I suspect they are thinking about things like cellular automata.

If you squint just right, you may think there are no conditionals. Just straight-line data flow to compute cell values based on a fixed neighborhood of the preceding state. A big fluid dynamics simulation has a similar characteristic.

However, this squinty interpretation can just as simply show you that the whole thing is just a DFA, as mentioned a few posts up! The finite mutable register just encodes the name of each state in the state machine, and each simulation cycle is just computing the next state transition within that large but finite state space.

But cellular automata have conditionals. That is the entire point of having a state in each cell and then doing something based on that state.
I suspect the confusion in this thread really boils down to a lack of agreement about what "conditional" means. I think some commenters above think it means conditionally branched instruction streams. They don't consider arithmetic or logical operators, lookup tables, and demuxers to be conditionals.

The earlier description of a cycle of functional updates to state sounds like the classic basis for latched digital circuit design. But, assuming the commenters were interested in software examples, I brought up analogous programs for cellular automata and grid simulations.

Also, since the state transition is purely functional with a finite input and output, it could theoretically be implemented with any functionally equivalent method, including flat lookup tables. No branching or conditional execution is required, even though it might be convenient.

Yeah true but I wouldn't call storing every possible result of a system in for instance a lookup table a computation. That is just precomputing all the results and then running a lookup.

If I have a lookup table of all the values of the sine and then use that lookup table to get the result of sine for specific value I haven't computed sine, I just looked it up.