Adding Odd Numbers
Math capability prompt example
TL;DR
- This is a simple
math reasoningtest: first filter (pick odd numbers), then add them, then judge parity (odd/even). - Good for observing: whether the model follows steps, whether it makes intermediate calculation errors, and whether it stays consistent.
- In production: require output of intermediate results at each step (list, summation process, final conclusion) for easier
evaluation.
Background
This prompt tests an LLM's mathematical capabilities by asking it to check whether the odd numbers in a group add up to an even number. It also nudges the model to break the problem into steps.
How to Apply
Treat this prompt as a "step-by-step execution" template:
- Identify (filter odd numbers)
- Compute (sum them)
- Verify (check if result is odd/even)
To migrate this to business calculation tasks, the key is: make each step a verifiable sub-task, and require intermediate results in the output.
How to Iterate
- Structured output: require a small table
numbers/is_odd/included/running_sum - Add
self-check: repeat the sum at the end, or re-compute in a different order - Control temperature (math tasks generally benefit from lower temperature for consistency)
- Adversarial testing: make the list longer, add invalid characters or more complex formatting, test robustness
Self-check Rubric
- Did it correctly identify which numbers are odd?
- Is the sum correct? Any intermediate step errors?
- Is the final parity judgment consistent with the sum?
- Does the output include verifiable intermediate results?
Practice
Exercise: apply the same template to these two task types:
- From a mixed input, extract numbers meeting a condition (e.g., divisible by 3), then sum
- Given a list of dates, filter out weekends, then count
Prompt
The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.
Solve by breaking the problem into steps. First, identify the odd numbers, add them, and indicate whether the result is odd or even.
Code / API
OpenAI (Python)
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "user",
"content": "The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.\nSolve by breaking the problem into steps. First, identify the odd numbers, add them, and indicate whether the result is odd or even.",
}
],
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
)
Fireworks (Python)
import fireworks.client
fireworks.client.api_key = "<FIREWORKS_API_KEY>"
completion = fireworks.client.ChatCompletion.create(
model="accounts/fireworks/models/mixtral-8x7b-instruct",
messages=[
{
"role": "user",
"content": "The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.\nSolve by breaking the problem into steps. First, identify the odd numbers, add them, and indicate whether the result is odd or even.",
}
],
stop=["<|im_start|>", "<|im_end|>", "<|endoftext|>"],
stream=True,
n=1,
top_p=1,
top_k=40,
presence_penalty=0,
frequency_penalty=0,
prompt_truncate_len=1024,
context_length_exceeded_behavior="truncate",
temperature=0.9,
max_tokens=4000,
)