If you're optimizing for an architecture on which branching is expensive (say the PS3's cell processor), it can be important to be able to determine whether or not you can express a given algorithm without using branches or at least using fewer branches. One pattern that I see a lot in unoptimized code is a bunch of if's used to tweak an index into some array (if the size of the array is odd, bump the index by 1, under some other circumstance, multiply by 2, etc.). So it would be nice if there were a way, given two lists of numbers, to be able to determine whether or not it's possible to write a branchless function transforming one list into the other.
For example I recently wanted to know if it was possible to write a branchless function that would transform: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
to: 0, 2, 4, 6, 8, 9, 7, 5, 3, 1
(ascending even followed by descending odd). Technically, I could write a big switch/case function but obviously I'm interested in a function that will follow the pattern for arbitrary sizes. Writing a function to do this transformation is straightforward with branching, but if there's a nonbranching way to do it it's not immediately obvious.
So is there a general approach to this sort of problem, or any sort of quick litmus test? Or do you have to come up with proofs on a case by case basis? I could work harder at these sorts of problems but that's pointless if they're literally impossible. I seem to recall reading at some point that there's a formal mathematical word for functions that only use arithmetic without branching, but I can't recall.