Math & logic problems

Reasoning shines on complex math and logic problems. Use low temperature (0.2-0.3) for focused, deterministic reasoning. Give the model enough max_tokens (1500-2000) to show all its work.

Reasoning model thinking

How reasoning models solve complex problems step by step

Yes, reasoning uses more output tokens because the AI writes out each step. A simple answer might be 20 tokens, while a reasoned answer could be 200-500 tokens. That is why we set max_tokens higher (1500-2000) for reasoning tasks and only use it when accuracy matters more than cost.

06-reasoning-models.ipynb
python
problem = "What is the sum of the first 10 prime numbers?"

solution = solve_with_reasoning(problem, temperature=0.3)
print(solution)
# Step 1: Identify first 10 primes
#   2, 3, 5, 7, 11, 13, 17, 19, 23, 29
# Step 2: Add them up
#   2+3=5, 5+5=10, 10+7=17, 17+11=28,
#   28+13=41, 41+17=58, 58+19=77, 77+23=100,
#   100+29=129
# Step 3: Verify - count (10 primes ✓), sum (129 ✓)
# Final answer: 129

The AI identifies all 10 primes, adds them step by step, and verifies both the count and the sum.

Now a logic puzzle. These require systematic elimination of possibilities rather than calculation. The AI must check each constraint one by one to find the valid arrangement.

06-reasoning-models.ipynb
python
logic_puzzle = """
Three friends - Alice, Bob, and Carol - are standing in a line.
- Alice is not first
- Bob is not last
- Carol is not in the middle

What is the order?
"""

solution = solve_with_reasoning(logic_puzzle, temperature=0.3)
# Step 1: List possible positions for each person
# Step 2: Alice not first → Alice is 2nd or 3rd
# Step 3: Bob not last → Bob is 1st or 2nd
# Step 4: Carol not middle → Carol is 1st or 3rd
# Step 5: If Bob is 1st, Alice must be 2nd or 3rd.
#   Carol not middle, so Carol is 3rd, Alice is 2nd.
# Answer: Bob, Alice, Carol

Logic puzzles need systematic elimination. The AI tries each possibility and eliminates contradictions.

No! Simple questions don't need reasoning. "What is the capital of France?" → just answer "Paris." Use reasoning for: - Complex math (multi-step calculations) - Logic puzzles (constraint satisfaction) - Code debugging (tracing execution) - Decision analysis (weighing tradeoffs) Reasoning costs more tokens and takes longer. Use it strategically.

Matching exercise: Match problems to reasoning need

Loading practice…

Ordering exercise: Chain-of-thought reasoning steps

Loading practice…

You have seen how reasoning transforms math and logic problems with step-by-step thinking. Next, we will apply the same approach to code debugging and real-world decision analysis.