Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Synthesis tracing

โญโญ intermediateโณ 12 min read๐Ÿ“ Lesson 127 of 256

Two passes, one table: mutation passes poison later reads.

Synthesis reading โ€” trace a multi-machine program without running it:

public static int process(int[] nums) {
    int marked = 0;
    for (int i = 0; i < nums.length; i++) {
        if (nums[i] % 2 == 0) {
            nums[i] = nums[i] / 2;
            marked++;
        } else {
            nums[i] = nums[i] * 2 + 1;
        }
    }
    int total = 0;
    for (int v : nums) {
        total += v;
    }
    return total - marked;
}

// call: process({3, 4, 5})

The trace table (two passes, one table):

| i | in | even? | out | marked | | - | -- | ----- | --- | ------ | | 0 | 3 | no | 7 | 0 | | 1 | 4 | yes | 2 | 1 | | 2 | 5 | no | 11 | 0 |

Pass two: total = 7 + 2 + 11 = 20. Return 20 โˆ’ 1 = 19.

Two habits to keep: (1) the mutation pass CHANGES the array โ€” a second pass reads the mutated values, not the originals; (2) for-each in pass two is fine (read-only). Programs like this are 3โ€“4 MCQs on every exam, and the table finishes them all.