Composing control flow and formula rules for computing on grids