Skip to main content

Chapter 1: Chain-of-Thought Prompting

🎯 Learning Objectives​

  • Understand what Chain-of-Thought prompting is
  • Apply CoT to math, logic, and complex reasoning
  • Use "Let's think step by step" and similar triggers
  • Know when CoT helps vs. when it's unnecessary

What is Chain-of-Thought?​

Chain-of-Thought (CoT) prompting encourages the AI to show its reasoning process step by step, rather than jumping directly to an answer.

The Problem with Direct Answers​

Standard Prompt:
"If John has 3 apples and gives away half, then buys 5 more,
how many does he have?"

AI might answer: "6.5 apples" (incorrect, rushed calculation)

The CoT Solution​

CoT Prompt:
"If John has 3 apples and gives away half, then buys 5 more,
how many does he have? Let's think through this step by step."

AI answer:
Step 1: John starts with 3 apples
Step 2: He gives away half: 3 Γ· 2 = 1.5 apples given away
Step 3: He keeps: 3 - 1.5 = 1.5 apples
Step 4: He buys 5 more: 1.5 + 5 = 6.5 apples
Answer: 6.5 apples

Wait, that seems odd. Let me reconsider...
If "gives away half" means half of what he has: 3/2 = 1.5
He keeps 1.5, buys 5 more = 6.5 apples βœ“

CoT Triggers​

Simple Triggers​

"Let's think step by step."
"Let's work through this carefully."
"Think about this step by step."
"Break this down logically."
"Let's reason through this."

Structured CoT​

"Solve this problem:
1. First, identify what we know
2. Then, determine what we need to find
3. Show each calculation step
4. Verify the answer makes sense"

When to Use CoT​

Use CoT ForSkip CoT For
Math problemsSimple factual questions
Logic puzzlesCreative writing
Multi-step reasoningDefinition requests
Complex analysisStraightforward tasks
Decision makingQuick summaries

CoT Examples​

Math Problem​

Problem: A train travels from City A to City B at 60 mph.
The return trip is at 40 mph. The total distance is
240 miles (one way). What's the average speed for
the round trip?

Let's solve this step by step:

Step 1: Calculate time for first trip
- Distance: 240 miles
- Speed: 60 mph
- Time = 240/60 = 4 hours

Step 2: Calculate time for return trip
- Distance: 240 miles
- Speed: 40 mph
- Time = 240/40 = 6 hours

Step 3: Calculate total distance and time
- Total distance: 240 + 240 = 480 miles
- Total time: 4 + 6 = 10 hours

Step 4: Calculate average speed
- Average speed = Total distance / Total time
- Average speed = 480/10 = 48 mph

Answer: 48 mph (not 50 mph as simple average would suggest!)

Logical Reasoning​

Problem: All roses are flowers. Some flowers fade quickly.
Can we conclude that some roses fade quickly?

Let's think through this logically:

1. Statement 1: All roses are flowers
- Every rose is a flower
- But not every flower is a rose

2. Statement 2: Some flowers fade quickly
- There exist flowers that fade quickly
- We don't know which flowers

3. Analysis:
- The flowers that fade quickly could be roses
- OR they could be other flowers (tulips, etc.)
- We have no information linking roses specifically

4. Conclusion: No, we cannot conclude that some roses
fade quickly. The flowers that fade might be other
types of flowers, not roses.

Zero-Shot vs Few-Shot CoT​

Zero-Shot CoT​

Simply add the trigger phrase:

"[Problem] Let's think step by step."

Few-Shot CoT​

Provide examples with reasoning:

Example 1:
Q: If a shirt costs $20 and is 25% off, what's the price?
A: Let's think step by step.
- Original price: $20
- Discount: 25% of $20 = $5
- Final price: $20 - $5 = $15

Example 2:
Q: If a shirt costs $30 and is 20% off, what's the price?
A: Let's think step by step.
- Original price: $30
- Discount: 20% of $30 = $6
- Final price: $30 - $6 = $24

Now solve:
Q: If a shirt costs $45 and is 30% off, what's the price?
A:

Key Takeaways​

Summary
  1. CoT prompting shows reasoning steps, improving accuracy
  2. Use triggers like "Let's think step by step"
  3. Best for math, logic, and complex reasoning
  4. Can be zero-shot (trigger only) or few-shot (with examples)
  5. Verify the reasoning makes sense

← Back to Module 4 | Next: Role-Playing and Personas β†’