Working with LLMs

Reasoning Through Problems


Learning Objectives

  • You understand what chain-of-thought prompting is and how it improves reasoning.
  • You know techniques for eliciting step-by-step reasoning from language models.
  • You understand what reasoning models are and how they differ from standard language models.
  • You can identify when reasoning techniques are appropriate for a task.

When tasks require reasoning

Many tasks require reasoning that involves more than pattern matching or information retrieval: breaking down problems, applying logical steps, and working through solutions systematically. Mathematical calculations, logical puzzles, multi-step planning, and complex decision-making all benefit from explicit reasoning processes rather than direct pattern-based responses.

Older large language models failed at relatively simple arithmetic tasks (e.g., 23 + 47 + 4 - 2) because the models lacked the ability to perform multi-step calculations reliably. Modern models have improved but still struggle with complex reasoning without guidance.

Consider a practical example: baking chocolate cookies when you’re short on ingredients. Suppose a recipe that produces 50 cookies requires 200g of chocolate, 150g of butter, 2 dl of sugar, 1 egg, 3 dl of wheat flour, and a pinch of salt. If you only have 75g of butter, how many cookies can you make?

Let’s try asking the model using few-shot prompting to constrain the output format:

A chocolate cookie recipe that produces 50 cookies requires 200g of chocolate, 150g of butter, 2 dl of sugar, 1 egg, 3 dl of wheat flour, and a pinch of salt.
#####
I have all the ingredients, but I only have 100 grams of chocolate. How many cookies can I produce?
#####
Answer: 25
#####
I have all the ingredients, but I only have 0.2 dl of sugar. How many cookies can I produce?
#####
Answer: 5
#####
I have all the ingredients, but I only have 75 grams of butter. How many cookies can I produce?
#####
Answer:

12.5

The answer should be 25 cookies (since 75g is half of 150g, yielding half of 50 cookies). The model has failed to reason correctly about the proportion, despite the examples provided.

This illustrates a common challenge: while language models can perform many tasks remarkably well, they sometimes struggle with tasks requiring multi-step reasoning, particularly when the reasoning process isn’t explicitly demonstrated in the prompt.


Chain-of-thought prompting

Chain-of-thought (CoT) prompting asks a model to generate intermediate reasoning steps before an answer. This can improve performance on some tasks, as demonstrated in chain-of-thought prompting experiments. Its effectiveness depends on the model, task, and prompt.

Generated steps become context for subsequent token predictions. This gives the model space to work through intermediate results. However, a plausible explanation is not necessarily a faithful account of what caused the answer: research has demonstrated misleading chain-of-thought explanations. Check the steps and the final result rather than treating the explanation as proof of correctness.

Few-shot chain-of-thought

Let’s revise our cookie problem to include explicit reasoning in the examples:

A chocolate cookie recipe that produces 50 cookies requires 200g of chocolate, 150g of butter, 2 dl of sugar, 1 egg, 3 dl of wheat flour, and a pinch of salt.
#####
I have all the ingredients, but I only have 100 grams of chocolate. How many cookies can I produce?
#####
Answer: As 200 grams of chocolate yields 50 cookies, 100 grams of chocolate yields 25 cookies.
#####
I have all the ingredients, but I only have 0.2 dl of sugar. How many cookies can I produce?
#####
Answer: As 2 deciliters of sugar yields 50 cookies, 0.2 deciliters of sugar yields 5 cookies.
#####
I have all the ingredients, but I only have 75 grams of butter. How many cookies can I produce?
#####
Answer:

As the original recipe calls for 150 grams of butter to produce 50 cookies, having only 75 grams of butter would allow you to produce 25 cookies.

The examples demonstrate how to calculate the proportion. In this response, the model correctly calculates that 75g (half of 150g) produces 25 cookies (half of 50). One successful response illustrates the technique but does not establish that it will always work.

Zero-shot chain-of-thought

Surprisingly, chain-of-thought reasoning can be elicited without providing examples simply by adding phrases that prompt step-by-step thinking. The most well-known is “Let’s think step by step,” introduced in Large Language Models are Zero-Shot Reasoners in 2022. Variants like “Let’s work through this systematically” or “Let’s break this down” also work effectively.

A chocolate cookie recipe that produces 50 cookies requires 200g of chocolate, 150g of butter, 2 dl of sugar, 1 egg, 3 dl of wheat flour, and a pinch of salt.

I have only 75g of butter. How many cookies can I produce?

Let's think step by step

First, we need to calculate the ratio of the ingredients to determine how many cookies can be made with 75g of butter.

The original recipe calls for 150g of butter to produce 50 cookies.

To find out how many cookies can be made with 75g of butter, we can set up a proportion:

150g butter is to 50 cookies as 75g butter is to x cookies

150g/50 cookies = 75g/x cookies

Cross multiplying, we get:

150g * x = 75g * 50

150x = 3750

x = 3750 / 150

x = 25

So, with 75g of butter, you can produce 25 cookies.

This response includes a proportion and explicit mathematical steps. Such prompts can encourage useful intermediate calculations, but the effect varies across models and problems.

Try it out!

Using the AI chatbot, try asking it to perform mathematics. Start with simple arithmetic like 7+7, then gradually build to more complex calculations. The chatbot is powered by a fairly powerful model, so it should handle basic math correctly. If you find a scenario where it makes a mistake, try adding “Let’s think step by step” to see if that helps.


Tasks that benefit from explicit reasoning

0 / 5 points

Which tasks are most likely to benefit from chain-of-thought style reasoning? (Select all that apply)


Advanced reasoning techniques

Researchers have developed several extensions to basic chain-of-thought prompting that improve performance on particularly challenging problems.

Self-consistency

Self-consistency generates multiple reasoning paths for the same problem and selects the most common answer through majority voting. Instead of accepting the first response, the system:

  1. Generates several responses using chain-of-thought prompting with sampling to produce diversity; the number of responses is a design choice
  2. Extracts the final answer from each response
  3. Takes the majority vote among the answers as the final output

This approach can improve accuracy when different successful paths converge on the same answer while errors vary. However, responses from the same model can share the same misconception, so a majority can agree on a wrong answer. Agreement is not independent verification.

For example, asking a model to solve a complex math problem multiple times might yield:

  • Response 1: [reasoning steps] → Answer: 42
  • Response 2: [different reasoning steps] → Answer: 42
  • Response 3: [yet different reasoning steps] → Answer: 38
  • Response 4: [more reasoning steps] → Answer: 42
  • Response 5: [final reasoning steps] → Answer: 42

Self-consistency would select 42 as the final answer based on the majority vote (4 out of 5 responses).

The trade-off is additional computation and cost. Responses may be generated sequentially or in parallel, affecting latency differently. For important decisions, verify the selected answer using reliable evidence or appropriate tools.

Self-consistency for harder problems

0 / 5 points

Which statements about the self-consistency technique are accurate? (Select all that apply)

Tree of thoughts and graph of thoughts

Tree of thoughts extends chain-of-thought by exploring multiple reasoning paths simultaneously rather than committing to a single path. The approach:

  1. Generates several possible next reasoning steps from the current state
  2. Evaluates which steps seem most promising using a scoring mechanism
  3. Explores multiple branches in parallel
  4. Backtracks if a path seems unproductive based on evaluation
  5. Continues until reaching satisfactory solutions

This mirrors how humans approach complex problems — trying different approaches, evaluating progress at intermediate stages, and switching strategies if necessary rather than following a single path to completion.

Graph of thoughts generalizes this further by allowing reasoning paths to merge and diverge arbitrarily rather than following a strict tree structure. This enables more flexible exploration of solution spaces where insights from different reasoning paths can be combined.

These techniques are primarily research directions rather than widely-deployed practical tools, but they illustrate ongoing work to improve reasoning capabilities beyond linear chains of thought.

Tree and graph of thoughts

0 / 5 points

Which statements correctly characterize tree-of-thoughts and graph-of-thoughts methods? (Select all that apply)

Tool-augmented reasoning

Tool-augmented reasoning recognizes that language models shouldn’t solve all problems purely through text generation. For certain tasks — precise calculations, database queries, web searches, code execution — external tools are more reliable than the model’s internal reasoning capabilities.

In tool-augmented systems, the model:

  1. Recognizes when a tool would be helpful for solving part of the problem
  2. Generates a properly-formatted tool call with appropriate parameters
  3. Receives the tool’s output
  4. Incorporates that output into its ongoing reasoning
  5. Continues until the problem is solved

For example, when asked “What’s the 47th Fibonacci number?”, a tool-augmented model might:

  1. Recognize this requires precise calculation beyond its reliable capabilities
  2. Generate Python code to calculate Fibonacci numbers efficiently
  3. Execute that code using a code interpreter tool
  4. Receive the result: 2,971,215,073
  5. Return this precise answer with confidence

This approach combines the model’s language understanding and reasoning with the precision of computational tools, yielding more reliable results than pure text generation for many technical tasks.

Tool-augmented reasoning

0 / 5 points

Which statements describe effective tool-augmented reasoning with language models? (Select all that apply)


Reasoning models

Recent developments have introduced a new class of models specifically designed for reasoning: reasoning models that use extended inference-time computation to solve complex problems more reliably.

How reasoning models differ

Ordinary autoregressive generation already uses more computation for longer prompts and outputs. Reasoning models can additionally allocate generation to intermediate reasoning before the final answer. Depending on the model and surrounding system, this can involve:

  • Producing extensive chain-of-thought (or similar) reasoning that may not be shown to users but guides the final response. This internal reasoning can span thousands of tokens.

  • Sampling multiple reasoning paths and selecting among their answers, as in self-consistency. This is an optional system technique, not a required property of every reasoning model.

  • Generating checks or revisions of intermediate results. These may catch errors, but can also repeat or introduce mistakes.

Additional inference computation can improve task performance, at the cost of time and expense. It does not guarantee that the final answer is correct.

Reasoning models' inference process

0 / 5 points

Which of the following accurately describe how reasoning models handle inference compared to standard models? (Select all that apply)


Practical guidance for reasoning tasks

When approaching tasks that require reasoning, seek to balance accuracy, cost, and latency:

  1. Try direct prompting first: Many problems don’t require explicit reasoning techniques. Start with clear, direct prompts.
  2. Add “Let’s think step by step”: If direct prompting fails or produces uncertain results, zero-shot CoT is a low-cost next step.
  3. Use few-shot CoT: If zero-shot CoT is insufficient, provide explicit reasoning examples demonstrating the desired problem-solving approach.
  4. Consider reasoning models: For particularly complex problems where accuracy matters more than speed or cost.
  5. Apply advanced techniques: Self-consistency or tool augmentation for critical decisions requiring high confidence.

Regardless of the technique you end up with, always verify the outputs carefully.

Tic-tac-toe

0 / 10 points

When defining artificial intelligence at the start of the course, we used an algorithm for tic-tac-toe as an example. In this exercise, the algorithm should be applied symmetrically for either player: if the current turn is X, treat X as your mark and O as the opponent; if the current turn is O, treat O as your mark and X as the opponent.

Use the following priority order:

  1. If you can win on this move, make the winning move.
  2. If your opponent is about to win, block them.
  3. If this is your first move, place your mark in a corner square.
  4. If your opponent has taken the corner opposite one of your corners, choose a different free corner; otherwise, take the opposite corner if it is free.
  5. Otherwise, play in any free corner or, if no corners are available, a side square.

Write a prompt that instructs the large language model to play a next move in a game of tic-tac-toe given the current board state and information on whether it is playing as X or O. The output should be the coordinates of the move in (row, column) format, where both row and column are 0-indexed (i.e., the top-left square is (0, 0) and the bottom-right square is (2, 2) — without quotes — i.e. the format is “row, column”).

The structure of the input is always as follows:

Current turn: X
Board state:
X . O
. X .
O . .

The first line indicates whose turn it is (X or O), followed by the board state represented as a 3x3 grid. The model should analyze the board and determine the best move according to the algorithm outlined above, then output the move in the specified format.

For example, for the above, the output should be exactly “2, 2” (without quotes) since placing an X in the bottom-right corner would result in a win.

The model that is used to generate the output is the same that the AI chat uses. The tic-tac-toe position that the model should analyze is appended after your prompt.