Composite functions
function composition prompt example
#TL;DR(中文)
- 这是一个 的测试:给code
function composition与若干映射点,反推出codeg(x)=f^{-1}(x)的对应关系,再计算codef。codef(f(f(6))) - 适合用来测:模型是否能把 inverse mapping 处理正确、是否会在多次 composition 时出错。
- 落地建议:要求模型输出 mapping table,并在每一步 composition 后输出中间值。
#Background
This prompt tests an LLM's mathematical capabilities by prompting it to evaluate a function composition.
#How to Apply(中文)
建议按 “先建立映射,再逐步计算” 的流程:
- 由 得到:code
g(x)=f^{-1}(x)(也就是把codef(g(x)) = x的 pairs 反向得到codeg的 pairs)codef - 用表格列出 的 mapping(例如code
f,codef(5)=0等)codef(7)=4 - 依次计算 code
f(6) → f(f(6)) → f(f(f(6)))
#How to Iterate(中文)
- 强制输出 (结构化)后再给最终答案code
mapping table - 加 :把code
self-check与codef互相验证(检查codeg在给定点是否成立)codeg(f(x)) = x - 对抗测试:增加更多点、加入干扰点、或让 非单射的情况看模型是否能发现矛盾code
f
#Self-check rubric(中文)
- 是否正确理解 关系并构造了code
inverse的映射?codef - composition 是否逐步计算且中间值正确?
- 是否检查了映射是否一致(无冲突)?
#Practice(中文)
练习:把问题改成
f(f(2))f(f(f(9)))- mapping table
- 每一步中间值
- 简短的 consistency check
#Prompt
textSuppose g(x) = f^{-1}(x), g(0) = 5, g(4) = 7, g(3) = 2, g(7) = 9, g(9) = 6. What is f(f(f(6)))?
#Code / API
#OpenAI (Python)
pythonfrom openai import OpenAI client = OpenAI() response = client.chat.completions.create( model="gpt-4", messages=[ { "role": "user", "content": "Suppose g(x) = f^{-1}(x), g(0) = 5, g(4) = 7, g(3) = 2, g(7) = 9, g(9) = 6. What is f(f(f(6)))?", } ], temperature=1, max_tokens=256, 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": "Suppose g(x) = f^{-1}(x), g(0) = 5, g(4) = 7, g(3) = 2, g(7) = 9, g(9) = 6. What is f(f(f(6)))?", } ], 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, )