logo
P
Prompt Master

Prompt 大师

掌握和 AI 对话的艺术

Mathematics Prompts

Mathematical understanding prompts (overview)

This section covers prompts for testing and practicing LLM math capabilities. The goal isn't "compute fast" -- it's a verifiable, reusable, self-checkable math problem-solving workflow.


What Are Math Prompts?

Math prompts use clear constraints + verifiable steps to have the model complete calculations, reasoning, or proofs.

┌─────────────────────────────────────────────────────────────┐
│                     Math Prompt Flow                          │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│   Problem input  →   Break into steps  →   Calculate/reason  →   Verify result │
│  (conditions)       (split variables)      (step by step)       (self-check)   │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Why Math Prompts Matter

Use CaseSpecific ApplicationBusiness Value
EducationProblem walkthroughs, homework helpBetter understanding
Financial analysisInterest/yield/cost calculationsFewer calculation errors
Engineering estimatesResource/capacity/cost estimatesMore accurate decisions
Product dataA/B tests, conversion rate inferenceQuick hypothesis checks
Research supportDerivations, formula verificationReduced reasoning bias

Common Math Task Types

TypeTypical ProblemPrompt Focus
ArithmeticBasic operations, ratiosShow your work
AlgebraEquations, variable relationsDefine variables
FunctionsComposite functions, evaluationStep-by-step substitution
GeometryArea/volume/anglesComplete conditions
Probability/StatsExpected value, probabilityDefine sample space
Proofs/LogicContradiction/inductionState the rules

Core Prompt Structure

A stable math prompt usually has four parts:

Goal: What to solve
Conditions: Given information and constraints
Process: Must be step-by-step and verifiable
Format: Final answer output separately

General Template

You are a rigorous math tutor. Solve step by step.

Problem:
{problem}

Requirements:
1) List variables and known conditions first
2) Show step-by-step derivation/calculation with intermediate results
3) Output the final answer separately
4) Self-check: substitute the result back to verify

Output format:
- Known/Variables:
- Steps:
- Final answer:
- Self-check:

Quick Start: Basic Arithmetic

Prompt:

Calculate and show intermediate steps.
Problem: An item originally costs $80. What's the price after a 25% discount?

Output:

Original price 80, discount 25% = 0.25
Discount amount = 80 × 0.25 = 20
Discounted price = 80 - 20 = 60
Final answer: $60

Example 1: Algebraic Equation

Scenario: Solve a linear equation

Prompt:

Solve the equation and show each step:
2x + 5 = 17

Output:

2x + 5 = 17
2x = 17 - 5 = 12
x = 12 / 2 = 6
Final answer: x = 6

Example 2: Word Problem (Work Rate)

Scenario: Two people completing a task together

Prompt:

A can finish a task alone in 6 hours. B can finish it in 4 hours. How long does it take if they work together?
Requirements: Show rates and calculation process.

Output:

A's rate: 1/6 task/hour
B's rate: 1/4 task/hour
Combined rate: 1/6 + 1/4 = 2/12 + 3/12 = 5/12 task/hour
Time = 1 ÷ (5/12) = 12/5 hours = 2.4 hours
Final answer: 2.4 hours

Example 3: Function Substitution

Scenario: Composite function evaluation

Prompt:

Given f(x) = 2x + 1, g(x) = x^2 - 3.
Find f(g(2)). Show step-by-step substitution.

Output:

First compute g(2) = 2^2 - 3 = 4 - 3 = 1
Then compute f(g(2)) = f(1) = 2 × 1 + 1 = 3
Final answer: 3

Example 4: Basic Probability

Scenario: Simple event probability

Prompt:

A bag contains 3 red balls and 2 blue balls. If you draw 1 ball at random, what's the probability of drawing a red ball?
Requirements: Show sample space and calculation.

Output:

Total balls = 3 + 2 = 5
Red balls = 3
Probability = 3 / 5
Final answer: 3/5

Advanced Tips

  1. Restate the problem first: Reduces misreading.
  2. Unify units: Convert time/length/currency first, then calculate.
  3. Boundary check: Use extreme values for quick sanity checks.
  4. Require self-check: Substitute back or reverse-verify the result.
  5. Limit output length: Prevent divergent reasoning.

Common Problems & Solutions

ProblemCauseSolution
Wrong resultSkipped stepsForce step-by-step + intermediates
Misread problemUnclear conditionsRestate problem first
Unit confusionUndefined variablesList variables + units first
Output too longReasoning spiralsLimit number of steps
Can't verifyNo self-checkAdd "substitute to verify" step

API Examples

Python (OpenAI)

from openai import OpenAI

client = OpenAI()

def solve_math(problem: str) -> str:
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[
            {
                "role": "system",
                "content": "You are a rigorous math tutor. You must show step-by-step derivation and give a final answer."
            },
            {
                "role": "user",
                "content": f"Solve step by step, output the final answer separately:\n{problem}"
            }
        ],
        temperature=0,
        max_tokens=300
    )
    return response.choices[0].message.content.strip()

print(solve_math("2x + 5 = 17"))

Python (Claude)

import anthropic

client = anthropic.Anthropic()

def solve_math(problem: str) -> str:
    message = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=300,
        messages=[
            {
                "role": "user",
                "content": f"""You are a math tutor.
Requirements: Step-by-step derivation, clear intermediate results, final answer output separately.
Problem: {problem}"""
            }
        ]
    )
    return message.content[0].text.strip()

print(solve_math("A bag has 3 red and 2 blue balls. What's the probability of drawing red?"))

Hands-on Exercises

Exercise 1: Ratio and Discount

Original price $120. Apply a 20% discount first, then subtract $10. What's the final price?
Requirements: step-by-step calculation + final answer.

Exercise 2: Composite Function

f(x) = x + 4, g(x) = 3x - 2.
Find g(f(5)). Show step-by-step substitution.

Exercise 3: Word Problem to Formula

A car travels at 60 km/h for 2.5 hours. How far does it go?
Requirements: write the formula first, then substitute and calculate.


Takeaways

  1. Math prompts need to emphasize step-by-step reasoning + self-check.
  2. List variables and conditions before computing.
  3. Fixed output format makes reuse and batch testing easier.
  4. Low temperature produces more stable results.
  5. Build a reusable template library through examples and exercises.