{ "task": { "id": "case_113", "name": "invert_if_sorted", "summary": "Inverts the sequence if it is sorted in ascending order, otherwise leaves it unchanged.", "examples": [ { "input": [ "BOS", 6, 19, 28, 14, 10, 7, 28, 20, 6 ], "output": [ "BOS", 6.0, 19.0, 28.0, 14.0, 10.0, 7.0, 28.0, 20.0, 6.0 ] }, { "input": [ "BOS", 25, 18, 22, 10, 10, 23, 20, 3, 7 ], "output": [ "BOS", 25.0, 18.0, 22.0, 10.0, 10.0, 23.0, 20.0, 3.0, 7.0 ] }, { "input": [ "BOS", 24, 16, 26, 26, 9, 27, 27, 15, 14 ], "output": [ "BOS", 24.0, 16.0, 26.0, 26.0, 9.0, 27.0, 27.0, 15.0, 14.0 ] }, { "input": [ "BOS", 1, 27, 20, 0, 11, 25, 21, 28, 11 ], "output": [ "BOS", 1.0, 27.0, 20.0, 0.0, 11.0, 25.0, 21.0, 28.0, 11.0 ] }, { "input": [ "BOS", 23, 2, 21, 20, 1, 23, 11, 29, 5 ], "output": [ "BOS", 23.0, 2.0, 21.0, 20.0, 1.0, 23.0, 11.0, 29.0, 5.0 ] } ], "is_categorical": true }, "program": "shifter = rasp.Select(rasp.indices, rasp.indices, lambda x, y: x == y - 1 or (x == 0 and y == 0))\nshifted = rasp.Aggregate(shifter, rasp.tokens)\nchecks = rasp.SequenceMap(lambda x, y: 1 if x <= y else 0, shifted, rasp.tokens)\nzero_selector = rasp.Select(checks, rasp.Map(lambda x: 0, rasp.indices), rasp.Comparison.EQ)\ninvert_decider = rasp.Map(lambda x: 1 if x > 0 else -1, rasp.SelectorWidth(zero_selector))\navg_idx = rasp.Map(lambda x: x / 2 - 0.5, rasp.SelectorWidth(rasp.Select(rasp.indices, rasp.indices, rasp.Comparison.TRUE)))\ndiff_to_avg_idx = rasp.SequenceMap(lambda x, y: x - y, rasp.indices, avg_idx)\ninverter = rasp.SequenceMap(lambda x, y: x + y, avg_idx, rasp.SequenceMap(lambda x, y: x * y, invert_decider, diff_to_avg_idx))\ninvert_selector = rasp.Select(inverter, rasp.indices, rasp.Comparison.EQ)\nreturn rasp.Aggregate(invert_selector, rasp.tokens)", "components": [ { "id": "L0H0_ATTN", "hook": "blocks.0.attn.hook_result[0]", "role": { "tag": "AGGREGATOR", "note": "Counts the number of non-increasing steps in the sequence by attending over positions where the sortedness check fails" }, "rasp_vars": [ "shifter" ], "labels": [ "selector_width_6_selector_width_attn_output" ] }, { "id": "L0H1_ATTN", "hook": "blocks.0.attn.hook_result[1]", "role": { "tag": "ROUTER", "note": "Produces the shifted token stream that aligns each token with its predecessor." }, "rasp_vars": [ "shifted" ], "labels": [ "aggregate_14" ] }, { "id": "L0_MLP", "hook": "blocks.0.mlp.hook_post", "role": { "tag": "MAPPER", "note": "Converts the attention-derived selector-width signal into sortedness evidence used by the global invert/keep decision." }, "rasp_vars": [ "checks", "zero_selector" ], "labels": [ "selector_width_6", "selector_width_6_selector_width_attn_output", "map_13" ] }, { "id": "L1_MLP", "hook": "blocks.1.mlp.hook_post", "role": { "tag": "COMBINER", "note": "Converts the sortedness evidence into a single invert/keep control signal for the rest of the circuit." }, "rasp_vars": [ "checks", "invert_decider" ], "labels": [ "map_4", "sequence_map_12" ] }, { "id": "L2H0_ATTN", "hook": "blocks.2.attn.hook_result[0]", "role": { "tag": "AGGREGATOR", "note": "Provides the sequence-length-style signal that is later turned into a center index reference for inversion." }, "rasp_vars": [ "length_helper" ], "labels": [ "selector_width_10_selector_width_attn_output" ] }, { "id": "L2_MLP", "hook": "blocks.2.mlp.hook_post", "role": { "tag": "COMBINER", "note": "Turns the length/position information into a center reference and a per-position offset-from-center signal used for inversion arithmetic." }, "rasp_vars": [ "avg_idx", "diff_to_avg_idx" ], "labels": [ "selector_width_10", "selector_width_10_selector_width_attn_output", "sequence_map_8" ] }, { "id": "L3_MLP", "hook": "blocks.3.mlp.hook_post", "role": { "tag": "MAPPER", "note": "Prepares an intermediate numeric signal for building the inverted index mapping." }, "rasp_vars": [ "inversion_prep" ], "labels": [ "map_7" ] }, { "id": "L4_MLP", "hook": "blocks.4.mlp.hook_post", "role": { "tag": "COMBINER", "note": "Combines the center reference, per-position offset, and the invert/keep control to produce the target source index for each position." }, "rasp_vars": [ "inverter" ], "labels": [ "sequence_map_5" ] }, { "id": "L5_MLP", "hook": "blocks.5.mlp.hook_post", "role": { "tag": "COMBINER", "note": "Finalizes the per-position index routing plan that will be used to either invert the sequence or leave it unchanged." }, "rasp_vars": [ "invert_selector" ], "labels": [ "sequence_map_3" ] }, { "id": "L6H0_ATTN", "hook": "blocks.6.attn.hook_result[0]", "role": { "tag": "ROUTER", "note": "Executes the final token movement: each position copies from its computed source index, yielding either the inverted or original sequence." }, "rasp_vars": [ "output" ], "labels": [ "aggregate_1" ] } ] }