I notice in my R console that x=sample(1:n); all(order(order(x)) == x) always evaluates TRUE, for any n. Just to assure you I'm not on the wrong SE site here, I know exactly what the code means, but this still makes my brain hurt. Can anyone draw a picture or give an explanatory proof to show what's going on?
Programming background
In R, sample scrambles a sequence, sampling without replacement, and order gives indices such that x[order(x)] is ascending. == does element-wise comparison, returning a vector of logical values. all returns TRUE for a list that's all TRUE and FALSE if the list contains any FALSE elements.
order(x)[order(order(x))]is sorted (setz = order(x)to see this). – eric_kernfeld May 06 '20 at 23:25