Indirect reasoning
proof-by-contradiction prompt template
#TL;DR(中文)
- 这是一个 模板:用code
indirect reasoning与codecontrapositive来刺激模型做更严谨的推理。codeproof-by-contradiction - 适合用于:数学证明、逻辑推导、以及“要证明某个结论必须成立”的场景。
- 落地关键是把步骤写成可执行的 checklist,并在最后做 (是否覆盖所有 cases、是否引入了未给定前提)。code
self-check
#Background
Zhang et al. (2024) proposed an indirect reasoning method that leverages contrapositives and contradictions. It consists of two key steps:
- augment data and rules to improve comprehensibility (e.g. logical equivalence of contrapositive)
- design prompt templates to stimulate proof-by-contradiction style reasoning
Below is an example of a zero-shot template for proof-by-contradiction.
#How to Apply(中文)
你可以把这个模板当成一个“证明型任务”的通用 scaffold:
- 把原命题拆成 conditions 与 question
- 合并条件形成一个更紧凑的集合(文中称 )code
wj - 在推理时显式考虑 ,并用 “intersection 是否为空” 来判断是否能构造反例code
negation of the question
它的价值在于:把模型的自由发挥变成“必须按步骤完成的推理流程”,降低跳步与偷换概念。
#How to Iterate(中文)
- 把 Step 1 的输出结构化:要求列出 /code
GivencodeTo Prove - 要求列出所有 cases(例如按符号、区间、边界值拆分)
- 在最后加 :逐条检查是否使用了未给定的假设(hidden assumptions)code
verification - 让模型输出 “failure mode”:如果不能证明,指出卡在哪里、需要补充哪些条件
#Self-check rubric(中文)
- 是否明确写出了 并使用code
negation推理?codecontradiction - 是否覆盖了所有 possibilities / cases?
- 是否引入了题目未给定的前提?
- 推理链条是否自洽(no circular reasoning)?
#Practice(中文)
练习:把下面任意一个命题用同样的
indirect reasoning- If is even, prove thatcode
a^2is even.codea - If , prove thatcode
x + |x| = 0.codex <= 0 - For any integer , ifcode
nis divisible by 4, thencodenis even.coden
#Prompt
textIf a+|a|=0, try to prove that a<0. Step 1: List the conditions and questions in the original proposition. Step 2: Merge the conditions listed in Step 1 into one. Define it as wj. Step 3: Let us think it step by step. Please consider all possibilities. If the intersection between wj (defined in Step 2) and the negation of the question is not empty at least in one possibility, the original proposition is false. Otherwise, the original proposition is true. Answer:
#Code / API
#OpenAI (Python)
pythonfrom openai import OpenAI client = OpenAI() response = client.chat.completions.create( model="gpt-3.5-turbo", messages=[ { "role": "user", "content": "If a+|a|=0, try to prove that a<0.\n\nStep 1: List the conditions and questions in the original proposition.\n\nStep 2: Merge the conditions listed in Step 1 into one. Define it as wj.\n\nStep 3: Let us think it step by step. Please consider all possibilities. If the intersection between wj (defined in Step 2) and the negation of the question is not empty at least in one possibility, the original proposition is false. Otherwise, the original proposition is true.\n\nAnswer:", } ], temperature=0, max_tokens=1000, top_p=1, frequency_penalty=0, presence_penalty=0, )
#Fireworks (Python)
pythonimport 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": "If a+|a|=0, try to prove that a<0.\n\nStep 1: List the conditions and questions in the original proposition.\n\nStep 2: Merge the conditions listed in Step 1 into one. Define it as wj.\n\nStep 3: Let us think it step by step. Please consider all possibilities. If the intersection between wj (defined in Step 2) and the negation of the question is not empty at least in one possibility, the original proposition is false. Otherwise, the original proposition is true.\n\nAnswer:", } ], 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, )