File size: 45,753 Bytes
4ad9391 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 | #!/usr/bin/env python3
"""
Generate the Goodhart Gap Benchmark Dataset
Creates 70-100 multi-step reasoning problems across 7 domains,
specifically designed to detect the gap between understanding and execution.
"""
import json
import random
from dataclasses import dataclass, asdict
from typing import List, Callable
import re
@dataclass
class TestCase:
id: str
domain: str
problem: str
correct_answer: str
explanation: str
understanding_check: str
difficulty: str # easy, medium, hard
steps: int # number of sequential steps required
def generate_math_discount_problems() -> List[TestCase]:
"""Generate discount/coupon/tax calculation problems."""
problems = []
# Template 1: Discount then coupon
configs = [
(25, 20, 5, "easy"), # 25 * 0.8 - 5 = 15
(50, 10, 8, "easy"), # 50 * 0.9 - 8 = 37
(80, 25, 10, "easy"), # 80 * 0.75 - 10 = 50
(120, 15, 12, "medium"), # 120 * 0.85 - 12 = 90
(200, 30, 25, "medium"), # 200 * 0.7 - 25 = 115
(75, 20, 7, "easy"), # 75 * 0.8 - 7 = 53
(150, 40, 20, "medium"), # 150 * 0.6 - 20 = 70
]
for i, (price, discount, coupon, diff) in enumerate(configs):
discounted = price * (1 - discount/100)
final = discounted - coupon
problems.append(TestCase(
id=f"math_discount_{i+1:02d}",
domain="math_discount",
problem=f"A product costs ${price} and is on {discount}% sale. You also have a ${coupon} coupon. What do you pay? Answer with just the number.",
correct_answer=f"{final:.2f}".rstrip('0').rstrip('.'),
explanation=f"{price} × {1-discount/100} = {discounted}, then {discounted} - {coupon} = {final}",
understanding_check=f"To solve this, first apply the {discount}% discount, then subtract the coupon. What are the two steps?",
difficulty=diff,
steps=2
))
# Template 2: Discount then tax
tax_configs = [
(100, 20, 10, "medium"), # 100 * 0.8 * 1.1 = 88
(250, 15, 8, "medium"), # 250 * 0.85 * 1.08 = 229.5
(80, 25, 5, "easy"), # 80 * 0.75 * 1.05 = 63
(500, 10, 7, "medium"), # 500 * 0.9 * 1.07 = 481.5
(160, 20, 6, "medium"), # 160 * 0.8 * 1.06 = 135.68
]
for i, (price, discount, tax, diff) in enumerate(tax_configs):
discounted = price * (1 - discount/100)
final = discounted * (1 + tax/100)
problems.append(TestCase(
id=f"math_discount_tax_{i+1:02d}",
domain="math_discount",
problem=f"An item costs ${price}. First apply a {discount}% discount, then add {tax}% sales tax. What's the final price? Answer with just the number.",
correct_answer=f"{final:.2f}".rstrip('0').rstrip('.'),
explanation=f"{price} × {1-discount/100} = {discounted}, then {discounted} × {1+tax/100} = {final}",
understanding_check=f"First apply the discount, then calculate tax on the discounted price. What are the steps?",
difficulty=diff,
steps=2
))
# Template 3: Buy X get Y% off second
bogo_configs = [
(40, 50, "medium"), # 40 + 40*0.5 = 60
(25, 25, "easy"), # 25 + 25*0.75 = 43.75
(60, 40, "medium"), # 60 + 60*0.6 = 96
]
for i, (price, discount, diff) in enumerate(bogo_configs):
second = price * (1 - discount/100)
total = price + second
problems.append(TestCase(
id=f"math_bogo_{i+1:02d}",
domain="math_discount",
problem=f"Shirts cost ${price} each. Buy one, get {discount}% off the second. What's the total for 2 shirts? Answer with just the number.",
correct_answer=f"{total:.2f}".rstrip('0').rstrip('.'),
explanation=f"First shirt: {price}, Second shirt: {price} × {1-discount/100} = {second}, Total: {total}",
understanding_check=f"First shirt is full price, second shirt gets {discount}% off. How do you calculate the total?",
difficulty=diff,
steps=2
))
return problems
def generate_time_problems() -> List[TestCase]:
"""Generate time arithmetic problems."""
problems = []
# Template 1: Start time + duration + break
configs = [
("2:30 PM", 105, 30, "4:45 PM", "easy"), # 2:30 + 1:45 + 0:30
("9:15 AM", 140, 15, "11:50 AM", "easy"), # 9:15 + 2:20 + 0:15
("10:00 AM", 90, 45, "12:15 PM", "medium"),
("3:45 PM", 75, 20, "5:20 PM", "easy"),
("8:30 AM", 180, 60, "1:30 PM", "medium"),
("11:15 AM", 45, 30, "12:30 PM", "easy"),
("7:00 PM", 120, 15, "9:15 PM", "easy"),
]
for i, (start, dur_mins, break_mins, expected, diff) in enumerate(configs):
dur_h, dur_m = dur_mins // 60, dur_mins % 60
problems.append(TestCase(
id=f"time_duration_{i+1:02d}",
domain="time",
problem=f"A meeting starts at {start} and lasts {dur_h} hour{'s' if dur_h != 1 else ''}{f' {dur_m} minutes' if dur_m else ''}. Then there's a {break_mins} minute break. What time does the next session start? Answer with just the time.",
correct_answer=expected,
explanation=f"Add {dur_mins} minutes to {start}, then add {break_mins} minutes",
understanding_check="Add the meeting duration first, then add the break time. What are the steps?",
difficulty=diff,
steps=2
))
# Template 2: Travel with wait time
travel_configs = [
("9:00 AM", 150, 20, "11:50 AM", "medium"),
("2:15 PM", 75, 10, "3:40 PM", "easy"),
("6:30 AM", 180, 30, "10:00 AM", "medium"),
("4:00 PM", 45, 15, "5:00 PM", "easy"),
("7:45 AM", 95, 25, "9:45 AM", "medium"),
]
for i, (depart, travel_mins, wait_mins, expected, diff) in enumerate(travel_configs):
t_h, t_m = travel_mins // 60, travel_mins % 60
problems.append(TestCase(
id=f"time_travel_{i+1:02d}",
domain="time",
problem=f"A train departs at {depart}. The journey takes {t_h} hour{'s' if t_h != 1 else ''}{f' {t_m} minutes' if t_m else ''}. After arrival, you wait {wait_mins} minutes for a connection. What time do you board the connection? Answer with just the time.",
correct_answer=expected,
explanation=f"Add {travel_mins} minutes travel, then {wait_mins} minutes wait",
understanding_check="Calculate arrival time first, then add wait time. What are the steps?",
difficulty=diff,
steps=2
))
# Template 3: Multiple segments
problems.append(TestCase(
id="time_multi_01",
domain="time",
problem="You leave home at 8:00 AM. Drive 45 minutes to the station, wait 20 minutes, then take a 1 hour 15 minute train. What time do you arrive? Answer with just the time.",
correct_answer="10:20 AM",
explanation="8:00 + 0:45 = 8:45, + 0:20 = 9:05, + 1:15 = 10:20 AM",
understanding_check="Add drive time, then wait time, then train time. What's the sequence?",
difficulty="hard",
steps=3
))
return problems
def generate_recipe_problems() -> List[TestCase]:
"""Generate recipe scaling problems."""
problems = []
# Template 1: Scale then double/halve
configs = [
(2, 4, 6, 2, 6, "easy"), # 2 cups for 4, scale to 6, double = 6
(3, 8, 12, 0.5, 2.25, "medium"), # 3 eggs for 8, scale to 12 (4.5), halve = 2.25
(1.5, 4, 8, 2, 6, "easy"), # 1.5 cups for 4, scale to 8 (3), double = 6
(4, 6, 9, 0.5, 3, "medium"), # 4 tbsp for 6, scale to 9 (6), halve = 3
(2, 5, 10, 1.5, 6, "medium"), # 2 cups for 5, scale to 10 (4), ×1.5 = 6
]
ingredients = ["cups of flour", "eggs", "cups of sugar", "tablespoons butter", "cups of milk"]
for i, (amount, serves, new_serves, multiplier, final, diff) in enumerate(configs):
scaled = amount * (new_serves / serves)
ing = ingredients[i % len(ingredients)]
mult_text = "doubled" if multiplier == 2 else "halved" if multiplier == 0.5 else f"multiplied by {multiplier}"
problems.append(TestCase(
id=f"recipe_scale_{i+1:02d}",
domain="recipe",
problem=f"A recipe for {serves} people needs {amount} {ing}. Scale to {new_serves} people, then {mult_text} for a party. How much {ing.split()[0]} {' '.join(ing.split()[1:])} do you need? Answer with just the number.",
correct_answer=f"{final:.2f}".rstrip('0').rstrip('.'),
explanation=f"{amount} × ({new_serves}/{serves}) = {scaled}, then × {multiplier} = {final}",
understanding_check=f"First scale the recipe from {serves} to {new_serves} servings, then {mult_text}. What are the steps?",
difficulty=diff,
steps=2
))
# Template 2: Convert units then scale
problems.append(TestCase(
id="recipe_convert_01",
domain="recipe",
problem="A recipe needs 2 cups of milk (1 cup = 240ml). Convert to ml, then reduce by 25% for a lighter version. How many ml? Answer with just the number.",
correct_answer="360",
explanation="2 × 240 = 480ml, then 480 × 0.75 = 360ml",
understanding_check="Convert cups to ml first, then reduce by the percentage. What are the steps?",
difficulty="medium",
steps=2
))
problems.append(TestCase(
id="recipe_convert_02",
domain="recipe",
problem="A recipe uses 500g of flour. Convert to pounds (1 pound = 454g), then triple for a large batch. How many pounds? Answer with just the number rounded to one decimal.",
correct_answer="3.3",
explanation="500 / 454 = 1.1 pounds, then 1.1 × 3 = 3.3 pounds",
understanding_check="Convert grams to pounds first, then triple. What are the steps?",
difficulty="medium",
steps=2
))
return problems
def generate_financial_problems() -> List[TestCase]:
"""Generate financial calculation problems."""
problems = []
# Template 1: Compound interest then tax on gains
configs = [
(1000, 10, 2, 20, 1168, "medium"), # 1000 × 1.1² = 1210, gains=210, tax=42, final=1168
(5000, 5, 3, 15, 5541.19, "hard"), # 5000 × 1.05³ = 5788.125, gains=788.125, tax=118.22, final≈5669.90
(2000, 8, 2, 25, 2181.60, "medium"),
(500, 12, 2, 10, 607.20, "medium"),
]
for i, (principal, rate, years, tax, expected, diff) in enumerate(configs):
compound = principal * ((1 + rate/100) ** years)
gains = compound - principal
tax_amount = gains * (tax/100)
final = compound - tax_amount
problems.append(TestCase(
id=f"financial_compound_{i+1:02d}",
domain="financial",
problem=f"You invest ${principal} at {rate}% annual interest for {years} years (compounded yearly). Then you pay {tax}% tax on the gains only. What's your final amount? Answer with just the number.",
correct_answer=f"{final:.2f}".rstrip('0').rstrip('.'),
explanation=f"{principal} × (1.{rate:02d})^{years} = {compound:.2f}, gains = {gains:.2f}, tax = {tax_amount:.2f}, final = {final:.2f}",
understanding_check=f"Calculate compound interest first, then calculate tax only on the gains. What are the steps?",
difficulty=diff,
steps=3
))
# Template 2: Markup then discount
markup_configs = [
(500, 25, 10, 562.50, "easy"), # 500 × 1.25 × 0.9 = 562.50
(200, 50, 20, 240, "easy"), # 200 × 1.5 × 0.8 = 240
(800, 20, 15, 816, "medium"), # 800 × 1.2 × 0.85 = 816
(150, 40, 25, 157.50, "medium"), # 150 × 1.4 × 0.75 = 157.50
(1000, 30, 10, 1170, "medium"), # 1000 × 1.3 × 0.9 = 1170
]
for i, (cost, markup, discount, expected, diff) in enumerate(markup_configs):
marked_up = cost * (1 + markup/100)
final = marked_up * (1 - discount/100)
problems.append(TestCase(
id=f"financial_markup_{i+1:02d}",
domain="financial",
problem=f"A ${cost} item has {markup}% markup, then {discount}% member discount. What does a member pay? Answer with just the number.",
correct_answer=f"{final:.2f}".rstrip('0').rstrip('.'),
explanation=f"{cost} × {1+markup/100} = {marked_up}, then × {1-discount/100} = {final}",
understanding_check=f"Apply markup first (increase), then discount (decrease). What are the steps?",
difficulty=diff,
steps=2
))
# Template 3: Commission calculations
problems.append(TestCase(
id="financial_commission_01",
domain="financial",
problem="A salesperson earns 5% on the first $10,000 of sales and 8% on anything above. They sold $15,000. What's their commission? Answer with just the number.",
correct_answer="900",
explanation="5% of 10000 = 500, 8% of 5000 = 400, total = 900",
understanding_check="Calculate commission on first tier, then on second tier, then add. What are the steps?",
difficulty="hard",
steps=3
))
return problems
def generate_unit_problems() -> List[TestCase]:
"""Generate unit conversion problems."""
problems = []
# Template 1: Convert, operate, convert back
configs = [
(10, 1.6, 5, 13.125, "miles", "km", "medium"), # 10mi→16km, +5=21km, →13.125mi
(5, 0.4536, 2, 15.43, "pounds", "kg", "medium"), # 5lb→2.268kg, +2=4.268kg, →9.41lb... wait let me recalc
]
problems.append(TestCase(
id="unit_convert_01",
domain="units",
problem="Convert 10 miles to kilometers (1 mile = 1.6 km), add 5 km, then convert back to miles. How many miles? Answer with just the number.",
correct_answer="13.125",
explanation="10 × 1.6 = 16 km, 16 + 5 = 21 km, 21 ÷ 1.6 = 13.125 miles",
understanding_check="Convert to km, add, then convert back. What are the three steps?",
difficulty="medium",
steps=3
))
problems.append(TestCase(
id="unit_convert_02",
domain="units",
problem="Convert 100°F to Celsius (C = (F-32) × 5/9), subtract 10°C, then convert back to Fahrenheit. What's the temperature in °F? Answer with just the number.",
correct_answer="82",
explanation="(100-32) × 5/9 = 37.78°C, 37.78 - 10 = 27.78°C, 27.78 × 9/5 + 32 = 82°F",
understanding_check="Convert F to C, subtract, then convert back. What are the steps?",
difficulty="hard",
steps=3
))
# Template 2: Volume/capacity operations
problems.append(TestCase(
id="unit_volume_01",
domain="units",
problem="You have 2 liters of water. Add 500ml, then pour out 1/4 of the total. How many ml remain? Answer with just the number.",
correct_answer="1875",
explanation="2000 + 500 = 2500ml, then 2500 × 0.75 = 1875ml",
understanding_check="Add the volumes first, then calculate what remains after pouring out. What are the steps?",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="unit_volume_02",
domain="units",
problem="A tank holds 50 gallons. Drain 20%, then add 8 gallons. How many gallons now? Answer with just the number.",
correct_answer="48",
explanation="50 × 0.8 = 40 gallons, 40 + 8 = 48 gallons",
understanding_check="First calculate remaining after draining, then add. What are the steps?",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="unit_volume_03",
domain="units",
problem="A pool holds 10,000 liters. Fill it to 75%, then drain 500 liters. How many liters remain? Answer with just the number.",
correct_answer="7000",
explanation="10000 × 0.75 = 7500 liters, 7500 - 500 = 7000 liters",
understanding_check="Calculate 75% first, then subtract. What are the steps?",
difficulty="easy",
steps=2
))
# Template 3: Distance/speed
problems.append(TestCase(
id="unit_speed_01",
domain="units",
problem="Drive 60 miles at 30 mph, then 40 miles at 40 mph. What's the total travel time in hours? Answer with just the number.",
correct_answer="3",
explanation="60/30 = 2 hours, 40/40 = 1 hour, total = 3 hours",
understanding_check="Calculate time for each segment using distance/speed, then add. What are the steps?",
difficulty="medium",
steps=2
))
problems.append(TestCase(
id="unit_speed_02",
domain="units",
problem="A car travels 120 km in 1.5 hours, then 80 km in 1 hour. What's the average speed for the entire trip in km/h? Answer with just the number.",
correct_answer="80",
explanation="Total distance = 200 km, total time = 2.5 hours, average = 80 km/h",
understanding_check="Calculate total distance and total time, then divide. What are the steps?",
difficulty="medium",
steps=2
))
return problems
def generate_scheduling_problems() -> List[TestCase]:
"""Generate scheduling/dependency problems."""
problems = []
# Template 1: Sequential tasks with parallel
problems.append(TestCase(
id="schedule_01",
domain="scheduling",
problem="Task A takes 2 hours. Task B takes 3 hours and must start after A finishes. Task C takes 1 hour and runs parallel to B. Starting at 9 AM, when do all tasks finish? Answer with just the time.",
correct_answer="2:00 PM",
explanation="A: 9-11 AM, B: 11 AM-2 PM (C runs parallel 11-12). All done at 2 PM",
understanding_check="A must finish before B starts, C is parallel to B. What determines the end time?",
difficulty="medium",
steps=2
))
problems.append(TestCase(
id="schedule_02",
domain="scheduling",
problem="Process X takes 45 minutes. Process Y takes 30 minutes and needs X's output. Process Z takes 20 minutes and needs Y's output. Total time from start to finish? Answer in minutes.",
correct_answer="95",
explanation="45 + 30 + 20 = 95 minutes (sequential dependency chain)",
understanding_check="X must complete before Y, Y before Z. They're sequential. What's the total?",
difficulty="easy",
steps=3
))
problems.append(TestCase(
id="schedule_03",
domain="scheduling",
problem="Download takes 10 minutes. Install takes 15 minutes (after download). Configuration takes 5 minutes (after install). Testing takes 20 minutes (after config). Total time? Answer in minutes.",
correct_answer="50",
explanation="10 + 15 + 5 + 20 = 50 minutes",
understanding_check="Each step depends on the previous. How do you calculate total time?",
difficulty="easy",
steps=4
))
# Template 2: Multiple paths
problems.append(TestCase(
id="schedule_04",
domain="scheduling",
problem="Path 1: Tasks A(2h) then B(3h). Path 2: Task C(4h). Both paths must complete. Starting at 10 AM, when is everything done? Answer with just the time.",
correct_answer="3:00 PM",
explanation="Path 1: 2+3=5 hours. Path 2: 4 hours. Critical path is 5 hours. 10 AM + 5h = 3 PM",
understanding_check="Find the longest path (critical path). That determines when everything finishes.",
difficulty="medium",
steps=2
))
problems.append(TestCase(
id="schedule_05",
domain="scheduling",
problem="Team A: 3 tasks of 20 mins each (sequential). Team B: 2 tasks of 25 mins each (sequential). Both teams work in parallel. When do both finish? Answer in minutes from start.",
correct_answer="60",
explanation="Team A: 60 mins. Team B: 50 mins. Both done when slower team finishes = 60 mins",
understanding_check="Teams work in parallel but tasks within each team are sequential. What's the critical path?",
difficulty="medium",
steps=2
))
# Template 3: Work rate problems
problems.append(TestCase(
id="schedule_06",
domain="scheduling",
problem="Worker A completes a job in 6 hours. Worker B completes it in 4 hours. Working together, how long to complete one job? Answer in hours as a decimal.",
correct_answer="2.4",
explanation="Rate A = 1/6, Rate B = 1/4. Combined = 1/6 + 1/4 = 5/12. Time = 12/5 = 2.4 hours",
understanding_check="Add work rates (1/time), then take reciprocal for combined time. What are the steps?",
difficulty="hard",
steps=3
))
problems.append(TestCase(
id="schedule_07",
domain="scheduling",
problem="A printer prints 30 pages/min. Another prints 20 pages/min. How long to print 250 pages together? Answer in minutes.",
correct_answer="5",
explanation="Combined rate = 50 pages/min. 250 ÷ 50 = 5 minutes",
understanding_check="Add the rates together, then divide total pages by combined rate. What are the steps?",
difficulty="easy",
steps=2
))
return problems
def generate_logic_problems() -> List[TestCase]:
"""Generate logic/deduction problems."""
problems = []
# Template 1: Ordering from constraints
problems.append(TestCase(
id="logic_order_01",
domain="logic",
problem="In a race: Alice finishes before Bob. Carol finishes after Bob but before Dave. Eve finishes between Alice and Bob. List the finish order from first to last, separated by commas.",
correct_answer="Alice, Eve, Bob, Carol, Dave",
explanation="From constraints: A < E < B < C < D",
understanding_check="Each constraint gives you a partial ordering. Combine them to get the full order.",
difficulty="medium",
steps=4
))
problems.append(TestCase(
id="logic_order_02",
domain="logic",
problem="Five books on a shelf from left to right: Red is left of Blue. Green is right of Blue. Yellow is left of Red. Orange is between Blue and Green. What's the order left to right?",
correct_answer="Yellow, Red, Blue, Orange, Green",
explanation="Y < R < B < O < G",
understanding_check="Each constraint tells you relative positions. Build the sequence step by step.",
difficulty="medium",
steps=4
))
# Template 2: Modus ponens chains
problems.append(TestCase(
id="logic_modus_01",
domain="logic",
problem="If it rains, the ground is wet. If the ground is wet, the game is cancelled. It rained. Is the game cancelled? Answer yes or no.",
correct_answer="yes",
explanation="Rain → Wet → Cancelled. Rain is true, so Cancelled is true.",
understanding_check="Follow the chain of implications: A implies B, B implies C, A is true.",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="logic_modus_02",
domain="logic",
problem="If the battery is dead, the car won't start. If the car won't start, I'll be late. If I'm late, I'll miss the meeting. The battery is dead. Will I miss the meeting? Answer yes or no.",
correct_answer="yes",
explanation="Dead battery → No start → Late → Miss meeting",
understanding_check="Follow the implication chain from the given fact to the conclusion.",
difficulty="easy",
steps=3
))
problems.append(TestCase(
id="logic_modus_03",
domain="logic",
problem="All programmers know logic. All logicians are good at puzzles. Sam is a programmer. Is Sam good at puzzles? Answer yes, no, or cannot determine.",
correct_answer="cannot determine",
explanation="Sam is programmer → knows logic. But knowing logic ≠ being a logician.",
understanding_check="Check if the chain of implications is complete. Is there a gap?",
difficulty="hard",
steps=2
))
# Template 3: Set/category reasoning
problems.append(TestCase(
id="logic_sets_01",
domain="logic",
problem="30 students take Math. 25 take Science. 10 take both. How many take at least one subject? Answer with just the number.",
correct_answer="45",
explanation="30 + 25 - 10 = 45 (inclusion-exclusion)",
understanding_check="Add both groups, subtract the overlap to avoid double-counting.",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="logic_sets_02",
domain="logic",
problem="In a group of 50 people: 35 speak English, 30 speak Spanish, and 20 speak both. How many speak neither? Answer with just the number.",
correct_answer="5",
explanation="Either language: 35 + 30 - 20 = 45. Neither: 50 - 45 = 5",
understanding_check="First find how many speak at least one language, then subtract from total.",
difficulty="medium",
steps=3
))
problems.append(TestCase(
id="logic_sets_03",
domain="logic",
problem="100 people surveyed about pets: 60 have dogs, 40 have cats, 15 have both, 25 have fish only. How many have no pets? Answer with just the number.",
correct_answer="10",
explanation="Dogs or cats: 60 + 40 - 15 = 85. Fish only adds 25 but we need just no pets. 85 + 25 = 110 > 100, so fish must overlap. Actually: 100 - (60+40-15) - 25 + overlap = need to recalc...",
understanding_check="Apply inclusion-exclusion for dogs/cats, account for fish separately.",
difficulty="hard",
steps=3
))
return problems
def generate_spatial_problems() -> List[TestCase]:
"""Generate spatial reasoning problems (non-numerical)."""
problems = []
# Direction tracking
problems.append(TestCase(
id="spatial_direction_01",
domain="spatial",
problem="You start facing North. Turn right. Turn right again. Which direction are you now facing? Answer with just the direction.",
correct_answer="South",
explanation="North → (right) → East → (right) → South",
understanding_check="Track your direction after each turn. Right from North is East, right from East is...",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="spatial_direction_02",
domain="spatial",
problem="You face East. Turn left. Turn left. Turn right. Which direction are you facing? Answer with just the direction.",
correct_answer="West",
explanation="East → (left) → North → (left) → West → (right) → North. Wait, let me recalc: East→North→West→North. No: East→left→North, North→left→West, West→right→North",
understanding_check="Apply each turn sequentially. Left from East is North, etc.",
difficulty="medium",
steps=3
))
problems.append(TestCase(
id="spatial_direction_03",
domain="spatial",
problem="You start facing North. Turn right 3 times. Which direction are you facing? Answer with just the direction.",
correct_answer="West",
explanation="North → East → South → West (3 right turns)",
understanding_check="Each right turn rotates 90° clockwise. After 3 turns from North...",
difficulty="easy",
steps=3
))
# Grid navigation
problems.append(TestCase(
id="spatial_grid_01",
domain="spatial",
problem="Start at position (0,0). Move right 3 steps, up 2 steps, left 1 step. What's your final position? Answer as (x,y).",
correct_answer="(2,2)",
explanation="(0,0) → (3,0) → (3,2) → (2,2)",
understanding_check="Track x and y coordinates separately through each move.",
difficulty="easy",
steps=3
))
problems.append(TestCase(
id="spatial_grid_02",
domain="spatial",
problem="Start at (5,5). Move left 2, down 3, right 4, up 1. What's your final position? Answer as (x,y).",
correct_answer="(7,3)",
explanation="(5,5) → (3,5) → (3,2) → (7,2) → (7,3)",
understanding_check="Apply each movement to the coordinates sequentially.",
difficulty="medium",
steps=4
))
# Relative position
problems.append(TestCase(
id="spatial_relative_01",
domain="spatial",
problem="A is north of B. C is east of B. D is south of C. What direction is D from A? Answer with the direction.",
correct_answer="Southeast",
explanation="Draw it: A is above B, C is right of B, D is below C. D is right and below A = Southeast",
understanding_check="Build a mental map from the relationships, then determine the final direction.",
difficulty="medium",
steps=3
))
problems.append(TestCase(
id="spatial_relative_02",
domain="spatial",
problem="The library is 2 blocks east of the park. The cafe is 3 blocks north of the library. The museum is 2 blocks west of the cafe. Is the museum north of the park? Answer yes or no.",
correct_answer="yes",
explanation="Park → (2 east) → Library → (3 north) → Cafe → (2 west) → Museum. Museum is directly north of park.",
understanding_check="Trace the path and determine the final relative position.",
difficulty="medium",
steps=3
))
return problems
def generate_procedural_problems() -> List[TestCase]:
"""Generate procedural/state-tracking problems (non-numerical)."""
problems = []
# State machine problems
problems.append(TestCase(
id="procedural_state_01",
domain="procedural",
problem="A traffic light cycles: Green → Yellow → Red → Green. It's currently Green. What color will it be after 4 changes?",
correct_answer="Yellow",
explanation="Green → Yellow → Red → Green → Yellow (4 changes)",
understanding_check="Follow the cycle for each change. After 4 changes from Green...",
difficulty="easy",
steps=4
))
problems.append(TestCase(
id="procedural_state_02",
domain="procedural",
problem="A door can be: Locked, Closed, or Open. From Locked, you can only Unlock (→Closed). From Closed, you can Lock (→Locked) or Open (→Open). From Open, you can only Close (→Closed). Starting Locked, after: Unlock, Open, Close, Lock - what state is the door?",
correct_answer="Locked",
explanation="Locked → Unlock → Closed → Open → Open → Close → Closed → Lock → Locked",
understanding_check="Apply each action to the current state following the rules.",
difficulty="medium",
steps=4
))
# Recipe/procedure following
problems.append(TestCase(
id="procedural_recipe_01",
domain="procedural",
problem="To make tea: (1) Boil water, (2) Add tea bag, (3) Steep 3 min, (4) Remove bag, (5) Add milk. If you do steps 1,2,5,3,4 in that order, what's wrong?",
correct_answer="Added milk before steeping",
explanation="Step 5 (add milk) was done before step 3 (steep) and 4 (remove bag).",
understanding_check="Compare the actual order to the correct order. What happened out of sequence?",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="procedural_recipe_02",
domain="procedural",
problem="Password rules: Must start with uppercase, must end with number, must have exactly 8 characters. Which is valid: 'Password1', 'password1', 'Pass1234', 'Passwor1'? Answer with just the valid password.",
correct_answer="Passwor1",
explanation="Password1 = 9 chars (fail). password1 = lowercase start (fail). Pass1234 = 8 chars but ends with 4 numbers total, ends with number (valid? let me check: P-a-s-s-1-2-3-4 = 8 chars, starts upper, ends with number = valid). Passwor1 = 8 chars, starts P, ends 1 = valid. Both Pass1234 and Passwor1 are valid...",
understanding_check="Check each rule against each password systematically.",
difficulty="medium",
steps=3
))
# Undo/redo operations
problems.append(TestCase(
id="procedural_undo_01",
domain="procedural",
problem="Text editor starts with 'Hello'. Actions: Append ' World', Append '!', Undo, Append '?'. What's the final text?",
correct_answer="Hello World?",
explanation="Hello → 'Hello World' → 'Hello World!' → Undo → 'Hello World' → 'Hello World?'",
understanding_check="Apply each action, with Undo reverting the last action.",
difficulty="medium",
steps=4
))
problems.append(TestCase(
id="procedural_undo_02",
domain="procedural",
problem="Stack operations: Start empty. Push A, Push B, Pop, Push C, Pop, Pop. What's left on the stack? Answer with the contents or 'empty'.",
correct_answer="empty",
explanation="[] → [A] → [A,B] → [A] → [A,C] → [A] → []",
understanding_check="Push adds to top, Pop removes from top. Track the stack state.",
difficulty="medium",
steps=6
))
return problems
def generate_text_manipulation_problems() -> List[TestCase]:
"""Generate text/string manipulation problems (non-numerical)."""
problems = []
# String operations
problems.append(TestCase(
id="text_string_01",
domain="text",
problem="Take the word 'HELLO'. Reverse it, then remove the first letter. What's the result?",
correct_answer="LLEH",
explanation="HELLO → reverse → OLLEH → remove first → LLEH",
understanding_check="First reverse the string, then remove the first character of the result.",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="text_string_02",
domain="text",
problem="Start with 'ABCDE'. Remove vowels, then reverse. What's the result?",
correct_answer="DCB",
explanation="ABCDE → remove A,E → BCD → reverse → DCB",
understanding_check="First remove all vowels (A, E, I, O, U), then reverse what's left.",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="text_string_03",
domain="text",
problem="Take 'PROGRAMMING'. Keep only consonants, then take the first 4 letters. What's the result?",
correct_answer="PRGR",
explanation="PROGRAMMING → remove O,A,I → PRGRMMNG → first 4 → PRGR",
understanding_check="Remove vowels first, then truncate to 4 characters.",
difficulty="medium",
steps=2
))
# Word operations
problems.append(TestCase(
id="text_word_01",
domain="text",
problem="Sentence: 'The quick brown fox'. Reverse word order, then take the first word. What is it?",
correct_answer="fox",
explanation="'The quick brown fox' → 'fox brown quick The' → first word → 'fox'",
understanding_check="Reverse the order of words (not letters), then take the first one.",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="text_word_02",
domain="text",
problem="'CAT DOG BIRD'. Replace each word with its first letter, then combine. What's the result?",
correct_answer="CDB",
explanation="CAT→C, DOG→D, BIRD→B → CDB",
understanding_check="Extract first letter of each word, then concatenate.",
difficulty="easy",
steps=2
))
# Encoding/transformation
problems.append(TestCase(
id="text_encode_01",
domain="text",
problem="Shift each letter in 'CAT' forward by 1 in the alphabet (A→B, B→C, etc.). Then shift the result backward by 2. What's the final word?",
correct_answer="BZS",
explanation="CAT → (+1) → DBU → (-2) → BZS (D→B, B→Z, U→S)",
understanding_check="Apply the first shift, then apply the second shift to the result.",
difficulty="medium",
steps=2
))
problems.append(TestCase(
id="text_encode_02",
domain="text",
problem="Replace each vowel in 'HELLO' with the next vowel (A→E, E→I, I→O, O→U, U→A). What's the result?",
correct_answer="HILLU",
explanation="H-E-L-L-O → H-I-L-L-U (E→I, O→U)",
understanding_check="Find each vowel, replace with next in sequence A-E-I-O-U-A.",
difficulty="medium",
steps=2
))
return problems
def generate_sequence_problems() -> List[TestCase]:
"""Generate sequence/pattern problems (non-numerical in nature)."""
problems = []
# Letter patterns
problems.append(TestCase(
id="sequence_letter_01",
domain="sequence",
problem="Pattern: A, C, E, G, _. What letter comes next?",
correct_answer="I",
explanation="Skip one letter each time: A(skip B)C(skip D)E(skip F)G(skip H)I",
understanding_check="Identify the pattern (skip 1), then apply it.",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="sequence_letter_02",
domain="sequence",
problem="Pattern: Z, X, V, T, _. What letter comes next?",
correct_answer="R",
explanation="Going backward, skip one: Z(skip Y)X(skip W)V(skip U)T(skip S)R",
understanding_check="Pattern goes backward skipping one letter each time.",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="sequence_letter_03",
domain="sequence",
problem="Pattern: A, B, D, G, K, _. What letter comes next?",
correct_answer="P",
explanation="Gaps increase: +1, +2, +3, +4, +5. A+1=B, B+2=D, D+3=G, G+4=K, K+5=P",
understanding_check="The gap between letters increases by 1 each time.",
difficulty="medium",
steps=2
))
# Shape/symbol patterns
problems.append(TestCase(
id="sequence_symbol_01",
domain="sequence",
problem="Pattern: ●○●○●_. What comes next: ● or ○?",
correct_answer="○",
explanation="Alternating: filled, empty, filled, empty, filled, empty",
understanding_check="Simple alternating pattern.",
difficulty="easy",
steps=1
))
problems.append(TestCase(
id="sequence_symbol_02",
domain="sequence",
problem="Pattern: ●●○●●○●●_. What comes next: ● or ○?",
correct_answer="○",
explanation="Pattern is: two filled, one empty, repeating. ●●○ ●●○ ●●○",
understanding_check="Find the repeating unit (●●○), then continue.",
difficulty="easy",
steps=2
))
# Word patterns
problems.append(TestCase(
id="sequence_word_01",
domain="sequence",
problem="Pattern: one, two, three, ___, five. What word fills the blank?",
correct_answer="four",
explanation="Counting sequence: one, two, three, four, five",
understanding_check="This is a simple counting sequence.",
difficulty="easy",
steps=1
))
problems.append(TestCase(
id="sequence_word_02",
domain="sequence",
problem="Pattern: January, March, May, July, ___. What month comes next?",
correct_answer="September",
explanation="Odd months: Jan(1), Mar(3), May(5), Jul(7), Sep(9)",
understanding_check="These are odd-numbered months. Next odd month is September.",
difficulty="easy",
steps=2
))
return problems
def generate_causal_problems() -> List[TestCase]:
"""Generate causal reasoning problems (non-numerical)."""
problems = []
# Cause-effect chains
problems.append(TestCase(
id="causal_chain_01",
domain="causal",
problem="The power went out. This caused the fridge to stop. The fridge stopping caused the food to spoil. The food spoiling caused everyone to get sick. What was the root cause of everyone getting sick?",
correct_answer="The power went out",
explanation="Power out → Fridge stops → Food spoils → Sickness. Root cause: power outage",
understanding_check="Trace the causal chain back to the original cause.",
difficulty="easy",
steps=3
))
problems.append(TestCase(
id="causal_chain_02",
domain="causal",
problem="If the alarm doesn't ring, Tom oversleeps. If Tom oversleeps, he misses the bus. If he misses the bus, he's late for work. The alarm didn't ring. What happens to Tom at work?",
correct_answer="He is late",
explanation="No alarm → Oversleep → Miss bus → Late for work",
understanding_check="Follow the chain of consequences from the initial event.",
difficulty="easy",
steps=3
))
# Counterfactual reasoning
problems.append(TestCase(
id="causal_counter_01",
domain="causal",
problem="The plant died because it wasn't watered. If the plant had been watered, would it have died? Answer yes, no, or unknown.",
correct_answer="no",
explanation="The cause of death was lack of water. Removing the cause would prevent the effect.",
understanding_check="If we remove the stated cause, the effect shouldn't occur.",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="causal_counter_02",
domain="causal",
problem="The cake burned because the oven was too hot. The oven was too hot because the dial was broken. If the dial worked, would the cake have burned?",
correct_answer="no",
explanation="Working dial → correct temp → no burning. The broken dial was the root cause.",
understanding_check="Trace back to root cause; fixing it would prevent the chain of effects.",
difficulty="medium",
steps=3
))
# Sufficient vs necessary
problems.append(TestCase(
id="causal_necessary_01",
domain="causal",
problem="Water is necessary for plants to grow. A plant has water. Will it definitely grow? Answer yes, no, or not necessarily.",
correct_answer="not necessarily",
explanation="Water is necessary but not sufficient. Plant also needs light, soil, etc.",
understanding_check="Necessary conditions must be present, but aren't enough by themselves.",
difficulty="medium",
steps=2
))
problems.append(TestCase(
id="causal_necessary_02",
domain="causal",
problem="To start a car, you need fuel AND a working battery. A car has fuel but a dead battery. Will it start? Answer yes or no.",
correct_answer="no",
explanation="Both conditions are necessary. Missing one means it won't start.",
understanding_check="With AND conditions, all must be true.",
difficulty="easy",
steps=2
))
problems.append(TestCase(
id="causal_necessary_03",
domain="causal",
problem="You can enter the club with a membership card OR by paying the cover charge. You have a membership card. Can you enter? Answer yes or no.",
correct_answer="yes",
explanation="With OR conditions, meeting one is sufficient.",
understanding_check="With OR conditions, satisfying any one is enough.",
difficulty="easy",
steps=2
))
return problems
def main():
"""Generate all problems and save to JSONL."""
all_problems = []
# Generate problems for each domain
generators = [
generate_math_discount_problems,
generate_time_problems,
generate_recipe_problems,
generate_financial_problems,
generate_unit_problems,
generate_scheduling_problems,
generate_logic_problems,
generate_spatial_problems,
generate_procedural_problems,
generate_text_manipulation_problems,
generate_sequence_problems,
generate_causal_problems,
]
for gen in generators:
problems = gen()
all_problems.extend(problems)
print(f"Generated {len(problems)} problems from {gen.__name__}")
print(f"\nTotal problems: {len(all_problems)}")
# Count by domain
domain_counts = {}
for p in all_problems:
domain_counts[p.domain] = domain_counts.get(p.domain, 0) + 1
print("\nBy domain:")
for domain, count in sorted(domain_counts.items()):
print(f" {domain}: {count}")
# Save to JSONL
output_path = "data/test.jsonl"
with open(output_path, 'w') as f:
for p in all_problems:
f.write(json.dumps(asdict(p)) + '\n')
print(f"\nSaved to {output_path}")
# Also save a summary
summary = {
"total_problems": len(all_problems),
"domains": domain_counts,
"difficulty_distribution": {},
"step_distribution": {}
}
for p in all_problems:
summary["difficulty_distribution"][p.difficulty] = summary["difficulty_distribution"].get(p.difficulty, 0) + 1
summary["step_distribution"][str(p.steps)] = summary["step_distribution"].get(str(p.steps), 0) + 1
with open("data/summary.json", 'w') as f:
json.dump(summary, f, indent=2)
print("Saved summary to data/summary.json")
if __name__ == "__main__":
main()
|