Hacker News new | ask | show | jobs
by rowanG077 2495 days ago
Can you provide an example? I have a hard time believing any arbitrary computation can be build without conditionals.
1 comments

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.

I'm not sure if we're actually debating anything at this point...

A cellular automaton or other grid simulation has modularity which means that the state space for one cell is relatively small. So, you might admit that the whole thing is doing computation without caring how the cell transition function is implemented?

But, lookup tables are at one extreme, and there are plenty of other design techniques for arbitrary functional computation that avoid conditional branching. At the digital design level, you can think of a continuum of logic gates where ROMs, mux/demux, or even ALU operations all have elements that can be seen as lookup-table or computation. The difference is in the observer's mental model, more so than in actual gate structures.

At the software level, many instructions can be used for demultiplexing. So, you can compute two different potential values, e.g. in separate registers, and select between results without branching. You could use a conditional-store instruction, or some kind of swizzle/pack instruction, but without any of that you could compute a binary test result, extend it to a whole register width, and use bitwise logical operations to combine both registers while effectively selecting one or the other. The essence of whether it is computation or conditional selection is in the eye of the beholder.

This is a common way to transform some code paths for vectorization, e.g. to generate one common SIMD instruction stream that has the effect of performing different optional computations in each lane, while actually running the same instructions on all lanes.