426 lines
10 KiB
Markdown
426 lines
10 KiB
Markdown
# Chain-of-Thought Reasoning Patterns
|
|
|
|
This reference provides comprehensive frameworks for implementing effective chain-of-thought (CoT) reasoning that improves model performance on complex, multi-step problems.
|
|
|
|
## Core Principles
|
|
|
|
### Step-by-Step Reasoning Elicitation
|
|
|
|
#### Problem Decomposition Strategy
|
|
- Break complex problems into manageable sub-problems
|
|
- Identify dependencies and relationships between components
|
|
- Establish logical flow and sequence of reasoning steps
|
|
- Define clear decision points and validation criteria
|
|
|
|
#### Verification and Validation Integration
|
|
- Include self-checking mechanisms at critical junctures
|
|
- Implement consistency checks across reasoning steps
|
|
- Add confidence scoring for uncertain conclusions
|
|
- Provide fallback strategies for ambiguous situations
|
|
|
|
## Zero-Shot Chain-of-Thought Patterns
|
|
|
|
### Basic CoT Initiation
|
|
```
|
|
Let's think step by step to solve this problem:
|
|
|
|
1. First, I need to understand what the question is asking for
|
|
2. Then, I'll identify the key information and constraints
|
|
3. Next, I'll consider different approaches to solve it
|
|
4. I'll work through the solution methodically
|
|
5. Finally, I'll verify my answer makes sense
|
|
|
|
Problem: {problem_statement}
|
|
|
|
Step 1: Understanding the question
|
|
{analysis}
|
|
|
|
Step 2: Key information and constraints
|
|
{information_analysis}
|
|
|
|
Step 3: Solution approach
|
|
{approach_analysis}
|
|
|
|
Step 4: Working through the solution
|
|
{detailed_solution}
|
|
|
|
Step 5: Verification
|
|
{verification}
|
|
|
|
Final Answer: {conclusion}
|
|
```
|
|
|
|
### Enhanced CoT with Confidence
|
|
```
|
|
Let me think through this systematically, breaking down the problem and checking my reasoning at each step.
|
|
|
|
**Problem**: {problem_description}
|
|
|
|
**Step 1: Problem Analysis**
|
|
- What am I being asked to solve?
|
|
- What information is provided?
|
|
- What are the constraints?
|
|
- My confidence in understanding: {score}/10
|
|
|
|
**Step 2: Strategy Selection**
|
|
- Possible approaches:
|
|
1. {approach_1}
|
|
2. {approach_2}
|
|
3. {approach_3}
|
|
- Selected approach: {chosen_approach}
|
|
- Rationale: {reasoning_for_choice}
|
|
|
|
**Step 3: Execution**
|
|
- {detailed_step_by_step_solution}
|
|
|
|
**Step 4: Verification**
|
|
- Does the answer make sense?
|
|
- Have I addressed all parts of the question?
|
|
- Confidence in final answer: {score}/10
|
|
|
|
**Final Answer**: {solution_with_confidence_score}
|
|
```
|
|
|
|
## Few-Shot Chain-of-Thought Patterns
|
|
|
|
### Mathematical Reasoning Template
|
|
```
|
|
Solve the following math problem step by step.
|
|
|
|
Example 1:
|
|
Problem: A store sells apples for $2 each and oranges for $3 each. If John buys 4 apples and 2 oranges, and spends exactly $14, how much does each fruit cost?
|
|
|
|
Step 1: Set up the equation
|
|
Let a = cost of apples, o = cost of oranges
|
|
4a + 2o = 14
|
|
|
|
Step 2: Simplify the equation
|
|
Divide both sides by 2: 2a + o = 7
|
|
|
|
Step 3: Test integer solutions
|
|
If a = 2, then 2(2) + o = 7 → o = 3
|
|
If a = 3, then 2(3) + o = 7 → o = 1
|
|
|
|
Step 4: Verify the original problem
|
|
For a=2, o=3: 4(2) + 2(3) = 8 + 6 = 14 ✓
|
|
For a=3, o=1: 4(3) + 2(1) = 12 + 2 = 14 ✓
|
|
|
|
Both solutions work, so apples could cost $2 and oranges $3, OR apples $3 and oranges $1.
|
|
|
|
Example 2:
|
|
Problem: Sarah is twice as old as Tom was 3 years ago. In 5 years, Sarah will be 1.5 times Tom's current age. How old are they now?
|
|
|
|
Step 1: Define variables
|
|
Let S = Sarah's current age, T = Tom's current age
|
|
|
|
Step 2: Set up equations
|
|
"Sarah is twice as old as Tom was 3 years ago": S = 2(T - 3)
|
|
"In 5 years, Sarah will be 1.5 times Tom's current age": S + 5 = 1.5T
|
|
|
|
Step 3: Solve the system
|
|
From first equation: S = 2T - 6
|
|
Substitute into second: (2T - 6) + 5 = 1.5T
|
|
2T - 1 = 1.5T
|
|
0.5T = 1
|
|
T = 2
|
|
|
|
Step 4: Find Sarah's age
|
|
S = 2(2) - 6 = 4 - 6 = -2
|
|
|
|
Step 5: Check for validity
|
|
Negative age is impossible, so I must have made an error.
|
|
Let me re-examine the problem...
|
|
|
|
Actually, let me try again:
|
|
S = 2(T - 3) = 2T - 6
|
|
S + 5 = 1.5T
|
|
Substitute: (2T - 6) + 5 = 1.5T
|
|
2T - 1 = 1.5T
|
|
0.5T = 1
|
|
T = 2 years old
|
|
S = 2(2 - 3) = 2(-1) = -2
|
|
|
|
This gives a negative age. The problem might have no solution with integer ages.
|
|
|
|
Now solve:
|
|
Problem: {math_problem}
|
|
|
|
Step 1: Define variables
|
|
{variable_definitions}
|
|
|
|
Step 2: Set up equations
|
|
{equation_setup}
|
|
|
|
Step 3: Solve the system
|
|
{solution_process}
|
|
|
|
Step 4: Verify the solution
|
|
{verification}
|
|
|
|
Final Answer: {answer}
|
|
```
|
|
|
|
### Logical Reasoning Template
|
|
```
|
|
Analyze the logical argument and determine if it's valid.
|
|
|
|
Example 1:
|
|
Premise 1: All birds can fly
|
|
Premise 2: Penguins are birds
|
|
Conclusion: Therefore, penguins can fly
|
|
|
|
Step 1: Analyze the structure
|
|
This is a syllogism with form:
|
|
All A are B
|
|
C is A
|
|
Therefore, C is B
|
|
|
|
Step 2: Evaluate premise validity
|
|
Premise 1: "All birds can fly" - This is false (penguins, ostriches cannot fly)
|
|
Premise 2: "Penguins are birds" - This is true
|
|
|
|
Step 3: Check logical validity
|
|
The logical structure is valid, but since Premise 1 is false, the conclusion may not be true
|
|
|
|
Step 4: Real-world verification
|
|
In reality, penguins cannot fly despite being birds
|
|
|
|
Conclusion: The argument is logically valid but soundness fails due to false premise
|
|
|
|
Example 2:
|
|
Premise 1: If it rains, then the ground gets wet
|
|
Premise 2: It is raining
|
|
Conclusion: Therefore, the ground gets wet
|
|
|
|
Step 1: Analyze the structure
|
|
This is modus ponens:
|
|
If P, then Q
|
|
P
|
|
Therefore, Q
|
|
|
|
Step 2: Evaluate premise validity
|
|
Premise 1: "If it rains, then the ground gets wet" - Generally true
|
|
Premise 2: "It is raining" - Given as true
|
|
|
|
Step 3: Check logical validity
|
|
Modus ponens is a valid argument form
|
|
|
|
Step 4: Verify the conclusion
|
|
Given the premises, the conclusion follows logically
|
|
|
|
Conclusion: The argument is both logically valid and sound
|
|
|
|
Now analyze:
|
|
Argument: {logical_argument}
|
|
|
|
Step 1: Analyze the argument structure
|
|
{structure_analysis}
|
|
|
|
Step 2: Evaluate premise validity
|
|
{premise_evaluation}
|
|
|
|
Step 3: Check logical validity
|
|
{validity_check}
|
|
|
|
Step 4: Verify the conclusion
|
|
{conclusion_verification}
|
|
|
|
Final Assessment: {argument_validity_assessment}
|
|
```
|
|
|
|
## Self-Consistency Techniques
|
|
|
|
### Multiple Reasoning Paths
|
|
```
|
|
I'll solve this problem using three different approaches and see which result is most reliable.
|
|
|
|
**Problem**: {complex_problem}
|
|
|
|
**Approach 1: Direct Calculation**
|
|
{first_approach_reasoning}
|
|
Result 1: {result_1}
|
|
|
|
**Approach 2: Logical Deduction**
|
|
{second_approach_reasoning}
|
|
Result 2: {result_2}
|
|
|
|
**Approach 3: Pattern Recognition**
|
|
{third_approach_reasoning}
|
|
Result 3: {result_3}
|
|
|
|
**Consistency Analysis:**
|
|
- Approach 1 and 2 agree: {yes/no}
|
|
- Approach 1 and 3 agree: {yes/no}
|
|
- Approach 2 and 3 agree: {yes/no}
|
|
|
|
**Final Decision:**
|
|
{majority_result} appears in {count} out of 3 approaches.
|
|
Confidence: {high/medium/low}
|
|
|
|
Most Likely Answer: {final_answer_with_confidence}
|
|
```
|
|
|
|
### Verification Loop Pattern
|
|
```
|
|
Let me solve this step by step and verify each step.
|
|
|
|
**Problem**: {problem_description}
|
|
|
|
**Step 1: Initial Analysis**
|
|
{initial_analysis}
|
|
|
|
Verification: Does this make sense? {verification_1}
|
|
|
|
**Step 2: Solution Development**
|
|
{solution_development}
|
|
|
|
Verification: Does this logically follow from step 1? {verification_2}
|
|
|
|
**Step 3: Result Calculation**
|
|
{result_calculation}
|
|
|
|
Verification: Does this answer the original question? {verification_3}
|
|
|
|
**Step 4: Cross-Check**
|
|
Let me try a different approach to confirm:
|
|
{alternative_approach}
|
|
|
|
Results comparison: {comparison_analysis}
|
|
|
|
**Final Answer:**
|
|
{conclusion_with_verification_status}
|
|
```
|
|
|
|
## Specialized CoT Patterns
|
|
|
|
### Code Debugging CoT
|
|
```
|
|
Debug the following code by analyzing it step by step.
|
|
|
|
**Code:**
|
|
{code_snippet}
|
|
|
|
**Step 1: Understand the Code's Purpose**
|
|
{purpose_analysis}
|
|
|
|
**Step 2: Identify Expected Behavior**
|
|
{expected_behavior}
|
|
|
|
**Step 3: Trace the Execution**
|
|
{execution_trace}
|
|
|
|
**Step 4: Find the Error**
|
|
{error_identification}
|
|
|
|
**Step 5: Propose Fix**
|
|
{fix_proposal}
|
|
|
|
**Step 6: Verify the Fix**
|
|
{fix_verification}
|
|
|
|
**Fixed Code:**
|
|
{corrected_code}
|
|
```
|
|
|
|
### Data Analysis CoT
|
|
```
|
|
Analyze this data systematically to draw meaningful conclusions.
|
|
|
|
**Data:**
|
|
{dataset}
|
|
|
|
**Step 1: Understand the Data Structure**
|
|
{data_structure_analysis}
|
|
|
|
**Step 2: Identify Patterns and Trends**
|
|
{pattern_identification}
|
|
|
|
**Step 3: Calculate Key Metrics**
|
|
{metrics_calculation}
|
|
|
|
**Step 4: Compare with Benchmarks**
|
|
{benchmark_comparison}
|
|
|
|
**Step 5: Formulate Insights**
|
|
{insight_generation}
|
|
|
|
**Step 6: Validate Conclusions**
|
|
{conclusion_validation}
|
|
|
|
**Key Findings:**
|
|
{summary_of_insights}
|
|
```
|
|
|
|
### Creative Problem Solving CoT
|
|
```
|
|
Generate creative solutions to this challenging problem.
|
|
|
|
**Problem:**
|
|
{creative_problem}
|
|
|
|
**Step 1: Reframe the Problem**
|
|
{problem_reframing}
|
|
|
|
**Step 2: Brainstorm Multiple Angles**
|
|
- Technical approach: {technical_ideas}
|
|
- Business approach: {business_ideas}
|
|
- User experience approach: {ux_ideas}
|
|
- Unconventional approach: {unconventional_ideas}
|
|
|
|
**Step 3: Evaluate Each Approach**
|
|
{approach_evaluation}
|
|
|
|
**Step 4: Synthesize Best Elements**
|
|
{synthesis_process}
|
|
|
|
**Step 5: Develop Final Solution**
|
|
{solution_development}
|
|
|
|
**Step 6: Test for Feasibility**
|
|
{feasibility_testing}
|
|
|
|
**Recommended Solution:**
|
|
{final_creative_solution}
|
|
```
|
|
|
|
## Implementation Guidelines
|
|
|
|
### When to Use Chain-of-Thought
|
|
- **Multi-step problems**: Tasks requiring sequential reasoning
|
|
- **Complex calculations**: Mathematical or logical derivations
|
|
- **Problem decomposition**: Tasks that benefit from breaking down
|
|
- **Verification needs**: When accuracy is critical
|
|
- **Educational contexts**: When showing reasoning is valuable
|
|
|
|
### CoT Effectiveness Factors
|
|
- **Problem complexity**: Higher benefit for complex problems
|
|
- **Task type**: Mathematical, logical, and analytical tasks benefit most
|
|
- **Model capability**: Newer models handle CoT more effectively
|
|
- **Context window**: Ensure sufficient space for reasoning steps
|
|
- **Output requirements**: Detailed explanations benefit from CoT
|
|
|
|
### Common Pitfalls to Avoid
|
|
- **Over-explaining simple steps**: Keep proportional detail
|
|
- **Circular reasoning**: Ensure logical progression
|
|
- **Missing verification**: Always include validation steps
|
|
- **Inconsistent confidence**: Use realistic confidence scoring
|
|
- **Premature conclusions**: Don't jump to answers without full reasoning
|
|
|
|
## Integration with Other Techniques
|
|
|
|
### CoT + Few-Shot Learning
|
|
- Include reasoning traces in examples
|
|
- Show step-by-step problem-solving demonstrations
|
|
- Teach verification and self-checking patterns
|
|
|
|
### CoT + Template Systems
|
|
- Embed CoT patterns within structured templates
|
|
- Use conditional CoT based on problem complexity
|
|
- Implement adaptive reasoning depth
|
|
|
|
### CoT + Prompt Optimization
|
|
- Test different CoT formulations
|
|
- Optimize reasoning step granularity
|
|
- Balance detail with efficiency
|
|
|
|
This framework provides comprehensive patterns for implementing effective chain-of-thought reasoning across diverse problem types and applications. |